I have a laravel component
<section class="section {{ $classes }}">
<div class="inner">
<h1>{{ $heading }}</h1>
<h2>{{ $subheading }}</h2>
<p>{{ $copy }}</p>
</div>
{{ $slot }}
</section>
I render in blade template
#component('components.section', ['classes' => 'lightgrey'])
#slot('heading')
The best thing ever....
#endslot
#slot('subheading')
#endslot
#slot('copy')
Lots of interesting words go here
#endslot
#endcomponent
Sometime I only have an H1. How can I remove the markup if I do not have a sub heading?
From the Laravel docs: https://laravel.com/docs/5.5/blade
The #isset and #empty directives may be used as convenient shortcuts for their respective PHP functions:
#isset($records)
// $records is defined and is not null...
#endisset
#empty($records)
// $records is "empty"...
#endempty
I'm thinking that this would probably work:
#isset($subheading)
#slot('subheading')
#endslot
#endisset
Related
Greetings I have an array of sections and the question related to that section looks like this
And I loop through that array and output the content to the screen here is the code
#foreach($sections as $section)
<div class="form-group">
<h2>{{ $section['section_name'] }}</h2>
<p>{{ $section['section_description'] }}</p>
<p>{{ $section['section_intro'] }}</p>
</div>
<div class="form-group ms-5">
#foreach($section['question'] as $question)
<h5>{{ $question['question_name'] }}</h5>
<p class="ms-3">{{ $question['question_description'] }}</p>
#endforeach
</div>
#endforeach
And the result of that looks like this
How can I remove this duplicate question_name I just want it to write it once, for example, it writes one Key Contracts and this two question_description under there for all of them?
#foreach($sections as $section)
<div class="form-group">
<h2>{{ $section['section_name'] }}</h2>
<p>{{ $section['section_description'] }}</p>
<p>{{ $section['section_intro'] }}</p>
</div>
<div class="form-group ms-5">
#php
$questions = [];
foreach($section['question'] as $question){
$questions[$question['question_name']][] = $question['question_description'];
}
#endphp
#foreach($questions as $question_name=>$question_descriptions)
<h5>{{ $question_name }}</h5>
#foreach($question_descriptions as $question_description)
<p class="ms-3">{{ $question_description }}</p>
#endforeach
#endforeach
</div>
#endforeach
I haven't tried it but I think it will work.
I'm storing the questions and descriptions in an array where the key is not an index but the name.
You could perhaps map the questions into groups by question name before sending to view. Something like this (for example purposes to get you started):
$sections = collect($sections)->map(function($section, $key){
return [
"section" => $section,
"grouped_questions"=> collect($section["question"])->mapToGroups(function($question, $key){
return [$question['question_name'] => $question];
})->toArray()
];
});
This will give you the questions grouped by their name.
I'm trying to work with livewire and i cant get it working.
I have a route:
Route::middleware(['auth:sanctum', 'verified'])
->get('/nuevoturno', NuevoTurno::class)
->name('nuevoturno');
The NuevoTurno.php contains:
namespace App\Http\Livewire;
use App\Models\FormatoTurno;
use Livewire\Component;
class NuevoTurno extends Component
{
public $qFecha = '2020-11-17';
public function render()
{
return view('livewire.nuevo-turno',[
'formatoTurno' => FormatoTurno::First()
]);
}
}
The livewire view:
#section('header', 'Nuevo Turno')
#section('content')
{{ $qFecha }}
<input type="text" value="{{ $qFecha }}">
<div>
<br>
{{-- A good traveler has no fixed plans and is not intent upon arriving. --}}
{{ $formatoTurno->Distancia_Entre_Turnos }}
{{ $formatoTurno->Hora_Inicio }}
{{ $formatoTurno->Hora_Fin }}
</div>
#endsection
{{ $qFecha }} is showing, but the input is not filled
So.. What's goin on?
EDIT:
I changed #section('content') to and in app.blade.php changed #yield('content') to {{ $slot }}
And now it appears:
< wire:id="BCEos1ECXtGL114CYnTn" wire:initial-data="{"fingerprint":{"id":"BCEos1ECXtGL114CYnTn","name":"nuevo-turno","locale":"es"},"effects":{"listeners":[]},"serverMemo":{"children":[],"errors":[],"htmlHash":"850cd1b2","data":{"qFecha":"2020-11-17"},"dataMeta":[],"checksum":"3cb32d8a817d51f7ff71a9ebeb184da10fb421dc1eb00e1ddd53a4ab30dcefb7"}}"!doctype html>
[SOLUTION]
I changed app.blade format from #yield() to {{ $slot }}.
Also changed livewire component nuevo-turno.blade:
<x-slot name="header">
Nuevo Turno
</x-slot>
<div>
{{ $qFecha }}
<input type="text" value="{{ $qFecha }}">
<div>
<br>
{{-- A good traveler has no fixed plans and is not intent upon arriving. --}}
{{ $formatoTurno->Distancia_Entre_Turnos }}
{{ $formatoTurno->Hora_Inicio }}
{{ $formatoTurno->Hora_Fin }}
</div>
</div>
And now it works.
Thanks everybody for the answers!
I am trying to edit a record in a table. I have created a route and the form, but I can't get past this error. I have figured out the problem but I can't find a fix. Am I correct in thinking that the edit.blade.php file needs the $ad->id passing?
The $ad->id is an ID of a specific add in a List View. The list view has all the tickets displayed from a table, and the below link is meant to edit that one item.
The edit route is accessed using following code:
Edit
I have one route that is supposed to open up the edit view form:
Route::get('/ticket_ads/edit/{ad}', 'TicketAdsController#editTicketAdForm')->name('ticket.edit');
The above route points to this in the controller:
public function editTicketAdForm($id)
{
//$ad = DB::table('ticket_ads')->where('id', $id)->value('id');
return view('Ads.edit')->with('id', $id);
}
This is the view called by the above function:
#extends('Shared.Layouts.MasterWithoutMenus')
#section('title')
Edit a ticket ad
#stop
#section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading"><h2>Edit your ticket ad</h2></div> <br/>
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
{{ Form::open(array('route' => 'ticket.edit', $id = 'id')) }}
<div class="form-group">
{{ Form::label('title', 'Title') }}
{{ Form::text('title', Input::old('title'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('comment', 'Comment') }}
{{ Form::text('comment', Input::old('comment'), array('class' => 'form-control')) }}
</div>
{{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
</div>
</div>
</div>
</div>
#endsection
This is the line that throws the error
{{ Form::open(array('route' => 'ticket.edit', $id = 'id')) }}
The ID displays normally in the URL as ticket_ads/edit/7 for example.
How do I get past this?
Change this line:
{{ Form::open(array('route' => 'ticket.edit', $id = 'id')) }}
to this:
{{Form::open(array('route' => array('ticket.edit', $id)))}}
This
{{ Form::open(array('route' => 'ticket.edit', $id = 'id')) }}
is wrong. Correct syntax is:
{{ Form::open(['route' => ['ticket.edit', $id]]) }}
also you should safely ditch using array() in favor of [] syntax as Laravel requires PHP 5.4+ anyway (unless you are using ancient version of Laravel, like v4?)
The correct syntax for calling route is.
{{ route('/cardetails', ['121','cars'] ) }}
In URL it will be like this below line.
127.0.0.1:8000/cardetails/121/cars
I recently created a commenting system for a blog. When there is one post in the blog, the commenting sytem works fine. However, when there are two posts on the blog, and I comment on the FIRST post, the comment shows up on the SECOND post. Similarily, if I add another post, so there are three posts in my blog, when I comment on the first post, the comment shows up under the third post. In the same situation, when I comment on the second post, the comment shows up under the third post. Here is my code:
/index.blade.php
#section('content')
<div class="col-md-8 col-md-offset-2">
<hr>
#foreach($posts as $post)
<h3>{{ $post->title}}</h3>
<p>by {{ $post->user->name }}</p>
<img src='{{ asset($post->image_path) }}' class="img-responsive" id="blogpic"/>
<p>{{ Str::words($post->body) }}</p>
<p>Read More...</p>
<hr>
{{ Form::open(array('action' => 'CommentController#newComment')) }}
{{ Form::hidden('post_id', $post->id) }}
<div class="row">
<div class="col-md-10">
{{ Form::text('body', null, array('class'=>'form-control')) }}
</div>
<div class="col-md-2">
{{ Form::submit('Post', array('class'=>'btn btn-info')) }}
</div>
</div>
<br>
#foreach($post->comments as $comment)
<div class="comment">
<p><span class="bold">{{ $comment->user->name }}</span>: {{ $comment->body }}</p>
</div>
#endforeach
#endforeach
</div>
#stop
Here is my new comment controller:
public function newComment()
{
$comment = New Comment();
$comment->user_id = Auth::user()->id;
$comment->post_id = $post_id = Input::get('post_id');
$comment->body = Input::get('body');
Post::find($post_id)->comments()->save($comment);
return Redirect::action('BlogController#index');
}
I am pretty sure the problem is in my index file, and I can provide more code if needed. My comment only seems to get the most recent id in this line
{{ Form::hidden('post_id', $post->id) }}
What could be going wrong?
Thanks in advance
I've created a page and then put this code
<section class="cont_pad">
<div class="container_12">
<article class="grid_8">
{{ blog:posts limit="5" offset="5" category="adultos" }}
<section class="post">
{{ if imagen_portada }}
<div class="postimg"><img src="{{ url:site }}files/thumb/{{ imagen_portada.id }}/610/220" class="pic2" alt="{{title}}" title="{{title}}"/></div>
{{ endif }}
<div class="entry-date">
<div class="posttime">
<h3>{{ helper:date timestamp=created_on }}</h3>
</div>
<div class="entry-utility">
{{ asset:image file="blog/icon1.png" }} {{ user:display_name user_id=author_id }}
<br/>
{{ if category }}
<span>{{ asset:image file="blog/icon2.png" }} {{ category:title }}</span>
{{ endif }}
{{ if keywords }}
<span>{{ asset:image file="blog/icon2.png" }} {{ keyword }}</span>
{{ endif }}
</div>
</div>
<div class="entry-text">
<h3 class="posttitle">{{ title }}</h3>
<div class="entry-content">
{{ intro }}
<p>{{ helper:lang line="blog:read_more_label" }}</p>
</div>
</div>
</section>
{{ /blog:posts }}
{{ pagination }}
</article>
<article class="grid_4 last-col">
<aside id="sidebar">
{{ widgets:area slug="widgets_blog_adultos" }}
</aside>
</article>
</div>
</section>
inside to show posts from category "adultos" but I'm not getting nothing. I have one post and it's LIVE in this category. What is wrong? I read Blog Plugin Docs also check the Blog Plugin Code at package "PyroCMS\Core\Modules\Blog\Plugins" and can't find where it fails. Also and related to this same question, can I paginate trough all the posts? I need some help here because I can't find what is wrong
Is the timezone on the computer set up wrong? If PyroCMS thinks the "Publish Date" is in the future it wont show it on the frontend.