laravel stop nested reply form in loop [closed] - laravel

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
how can i stop the reply form from showing and repeating its self after a reply has been made
#foreach($comments as $comment)
<div class="display-comment">
<strong>{{ $comment->user->name }}</strong>
<p>{{ $comment->comment }}</p>
<form method="post" action="{{ route('reply.add') }}">
#csrf
<div class="form-group">
<input type="text" name="comment" class="form-control" />
<input type="hidden" name="post_id" value="{{ $post_id }}" />
<input type="hidden" name="comment_id" value="{{ $comment->id }}" />
</div>
<div class="form-group">
<input type="submit" class="py-0 btn btn-sm btn-outline-danger" style="font-size: 0.8em;" value="Reply" />
</div>
</form>
#include('posts.comments.reply', ['comments' => $comment->replies])
</div>
#endforeach

#forelse($comments as $comment)
<div class="display-comment">
<strong>{{ $comment->user->name }}</strong>
<p>{{ $comment->comment }}</p>
#include('posts.comments.reply', ['comments' => $comment->replies])
</div>
#empty
<div> No comments found</div>
#endforelse
<form method="post" action="{{ route('reply.add') }}">
#csrf
<div class="form-group">
<input type="text" name="comment" class="form-control" />
<input type="hidden" name="post_id" value="{{ $post_id }}" />
<input type="hidden" name="comment_id" value="{{ $comment->id }}" />
</div>
<div class="form-group">
<input type="submit" class="py-0 btn btn-sm btn-outline-danger" style="font-size: 0.8em;" value="Reply" />
</div>
</form>

You should have be able to figure it out. It's not that tricky
#if (!empty($comment->replies))
#include('posts.comments.reply', ['comments' => $comment->replies])
#empty

Related

Build Laravel multistep form with foreach?

Good morning,
I want build a multistep form in Laravel and I discover a lot of tutorial on Youtube to make this but In my form, I use a Foreach because I build a exam system and I display Question and Response with foreach.
This is my Code :
<form method="POST" action="{{ route('stagiaire.session.test.store',['id'=>$eval->id]) }}">
#csrf
#foreach($questioncat as $category)
<div class="card mb-3">
<div class="card-header">{{ $category->nom }}</div>
<div class="card-body">
#foreach($category->getQuestion as $question)
<div class="card #if(!$loop->last)mb-3 #endif">
<div class="card-header">{{ $question->question_text }}</div>
<div class="card-body">
<input type="hidden" name="questions[{{ $question->id }}]" value="">
#foreach($question->reponse as $option)
<div class="form-check">
<input class="form-check-input" type="radio" name="questions[{{ $question->id }}]" id="option-{{ $option->id }}" value="{{ $option->id }}"#if(old("questions.$question->id") == $option->id) checked #endif>
<label class="form-check-label" for="option-{{ $option->id }}">
{{ $option->option_text }}
</label>
</div>
#endforeach
#if($errors->has("questions.$question->id"))
<span style="margin-top: .25rem; font-size: 80%; color: #e3342f;" role="alert">
<strong>{{ $errors->first("questions.$question->id") }}</strong>
</span>
#endif
</div>
</div>
#endforeach
</div>
</div>
#endforeach
<div class="form-group row mb-0">
<div class="col-md-6">
<button type="submit" class="btn btn-primary">
Submit
</button>
</div>
</div>
</form>
So my question, is it possible to build a multistep form with foreach?
Thanks
I am at the thinking stage

Can't pass data out of foreach in laravel

How can I export the data when I open a foreach in the application I developed in Laravel. For example, I want to filter after some id sync.
Blade/View
#foreach ($parts as $item)
#foreach ($country->getPerson ?? [] as $person)
#if ($country->id == $person->country_id)
#endif
#endforeach
#if ($loop->iteration == $person->part_id)
#continue
#endif
<div class="col-sm-6 col-lg-4">
<div class="service-item my-3">
<div class="service-wrapper m-0 bg-white">
<div class="service-content mt-3">
<h5 class="mb-3"> {{ $item->name }}</h5>
<a data-bs-toggle="modal" data-bs- target="#service1"
href="#" class="text-primary">
Alert!
<i class="fas fa-angle-right ms-2"> </i>
</a>
<br> <br>
<form class="call-to-action-form m-auto" action="{{ route('add.person') }}"
enctype="multipart/form-data" method="POST">
#csrf
<div class="input-group">
<input type="text" class="form-control" name="name"
placeholder="Adınız Soyadınız" required> <br>
<input type="text" class="form- control" name="email"
placeholder="E-Mail Adresiniz" required>
</div>
<input type="hidden" name="country_id" value="{{ $country->id }}" required>
<input type="hidden" name="part_id" value="{{ $item->part_id }}" required>
<br>
<button class="btn btn-success" type="submit">Cüzü Al
</button>
</form>
</div>
</div>
</div>
#endforeach
I want to return it here.
what I want to do is
{{person->part_id}}
by assigning its value outside the foreach
#if ($loop->iteration == $person->part_id)
#continue
#endif
My associated models run regularly. Now I need to filter the ids corresponding to my person table in my part table. The code sequence I shared above only takes the latest id. I cannot get other corresponding ids, so it only filters once.

Syntax error, unexpected end of file in my laravel code [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am using Laravel 6 to create an insert blade. When I wanted to display the view, it generated an error as shown below:
error:syntax error, unexpected end of file
With this code:
#extends('layouts.app')
#section('title','insert')
#section('content')
#if(session('message'))
<div class="">
{{session('message')}}
</div>
#endif
<br/>
<form class="" id="feedback_form" method="post" action="{{route('insert')}}">
<input type="hidden" name="_token" value="{{csrf_token()}}" />
<input type="hidden" name="id" value="" />
<div class="">
<label for="name" class=" ">Tên sản phẩm<span class=""> :</span></label>
<input type="text" name="name" class=""/>
</div>
<div class=" ">
<label for="name" class=" ">Mô tả<span class=""> :</span></label>
<input type="text" name="description" class=""/>
</div>
<div class=" ">
<label for="name" class=" ">Danh mục<span class=""> :</span></label>
<select name="cate">
#foreach($cate as $ca)
<option value="{{ $ca->id }}">{{ $ca->name }}</option>
</select>
</div>
<div class="">
<div class="">
<button class="btn btn-success" type="submit">SAVE</button>
<button class="btn btn-default" type="reset">Close</button>
</div>
</div>
</form>
#endsection
What's the problem?
Just put this code
you forgot to put #endforeach
<select name="cate">
#foreach($cate as $ca)
<option value="{{ $ca->id }}">{{ $ca->name }}</option>
#endforeach
</select>
when you write foreach in a blade file you need to end it by endforeach.same for if in blade file like endif.So here is your error for not endforeach.
Try this,
#foreach($cate as $ca)
<option value="{{ $ca->id }}">{{ $ca->name }}</option>
#endforeach

Laravel5.6 - after validation form fail, how to set up variable from parent view

i have a view named ('back.employee.detail') with an #includewhen('back.dossiers.create') into it.
my div for error is in 'back.employee.detail' :
<div class="alert {{ $type_alert }} alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria hidden="true">×</button>
<h4><i class="icon fa {{ $alert_icon }}"></i> Alert!</h4>
{{ $flash_message }}
</div>
my form is in my view 'back.dossiers.create' and inside i use $employee_detail :
<form method="POST" action="{{ route('create.document.employee.store', $employee_detail->id) }}" aria-label="{{ __('Create') }}">
#csrf
<div class="box-body">
<div class="form-group">
<label for="description">Description</label>
<input type="text" class="form-control {{ $errors->has('description') ? ' is-invalid' : '' }}"
name="description" id="description" value="{{ old('description') }}">
#if ($errors->has('description'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('description') }}</strong>
</span>
#endif
</div>
<div class="form-group">
<label for="commentaire">Commentaire</label>
<input type="text" class="form-control{{ $errors->has('commentaire') ? ' is-invalid' : '' }}"
name="commentaire" id="commentaire" value="{{ old('commentaire') }}">
#if ($errors->has('commentaire'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('commentaire') }}</strong>
</span>
#endif
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
For validation error, i used to have that in my controller :
return back()->withErrors($validator)
->withInput()
->with('flash_message',$flash_message)
->with('type_alert',$type_alert)
->with('alert_icon',$alert_icon)
->with('type_crud',$type_crud)
->with('employee_detail',$employee_detail);
but the variable flash_message , type_alert... are into the parent view.
i want to update value for flash_message,type_alert,alert_icon,employee_detail and also type_crud and employee_detail but flash message has not been updated.
Do you have an idea how to do it ?
Thanks
Your question is't very clear to me.
Maybe this examples will help you a bit:
Pass data using includeWhen:
#includeWhen($boolean, 'view.name', ['some' => 'data'])
#include('view.name', ['some' => 'data'])
Hope this helps.
Gut luck:)

How to validate without empty other filled fields Laravel

Hi there I have this fields:
<form role="form" class="form margin-bottom-0" action="{{ url('/test') }}" method="post" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="box box-widget widget-use padding-40 padding-top-0 box-shadow-none">
<div class="row">
<div class="col-md-6">
<div class="form-group floating-label {{ $errors->has('name') ? ' has-error' : '' }}">
<input class="form-control" name="name" id="regular2" type="text" value="#if($account){{$account['name']}} #endif" >
<label for="regular2" >#lang('payment.full_name')</label>
#if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
#endif
</div>
</div>
<div class="col-md-6">
<div class="form-group floating-label {{ $errors->has('address') ? ' has-error' : '' }}">
<input class="form-control" name="address" id="regular2" type="text" value="#if($account){{$account['address']}}#endif" >
<label for="regular2">#lang('payment.address')</label>
#if ($errors->has('address'))
<span class="help-block">
<strong>{{ $errors->first('address') }}</strong>
</span>
#endif
</div>
</div>
</div>
</div>
<button type="submit" class="btn save-lang savecard">#lang('buttons.save_changes')</button>
</form>
and when I submit it shows me the validation just fine
but when I fill one field and I submit the field that I put text on it empties, how can I make the text to stay..?
Try this on every inputs you have:
<input class="form-control" name="name" id="regular2" type="text" value="{{ old('name') }}" >
Just use old().
You can use the old method in your template referring the documentation
If you use $this->validate(/*your rules*/) in your controller, it will send the errors and the old input.
Then your can use for exemple :
<input class="form-control" name="name" id="regular2" type="text" value="{{ old('name') }}" > To make the text stay.
Hopes it helps you.

Resources