I am doing a validation of a form in Laravel.
In this form I have two inputs (one text and one checkbox).
But I have two lists, in which I can move the elements from one list to another and order them.
But I don't know how to send these lists through the form to the Laravel validation.
Thanks in advance
My form:
<form id="create-menu-opac" action="{{ route('post_create_menu_opac')}}" method="post" role="form" autocomplete="off">
{{ csrf_field() }}
...
<section>
<div class="row">
<div class="col-sm-6">
<h6>{{ trans('menu-opac.buttons_avaiable') }}</h6>
<ul id="buttons_no_selected" class="list-group list-group-sortable-connected connected">
#foreach ($buttons as $button)
<li id="{{$button->id}}" class="list-group-item list-group-item-info">{{$button->description}}</li>
#endforeach
</ul>
</div>
<div class="col-sm-6">
<h6>{{ trans('menu-opac.items_menu') }}</h6>
<ul id="buttons_selected" class="list-group list-group-sortable-connected connected">
</ul>
</div>
</div>
</section>
...
</form>
This two lists work with a library Jquery and Boostrap
My controller
foreach ($request as $_request) {
Log::Debug(print_r($_request,true));
}
In this Log I can see the two inputs (type text and type checkbox), but i can't see the list.
Try adding input hidden in your blade file then see if you get the data in your $request
#foreach ($buttons as $button)
<li id="{{$button->id}}" class="list-group-item list-group-item-info">{{$button->description}}</li>
<input type="hidden" id="{{$button->id}}" value="{{$button->description}}" name="{{$button->description}}">
#endforeach
Related
i have a property model and i want to get the property show method and do some operation on it so i am on the show method right now consider the link below :
http://localhost:8000/properties/1
now from this link i submit a form to the route below :
Route::post('/properties/startreserve','PropertyController#startreserve');
and this is the controller of my startreserve and here i want to get the property that i had in last page which means property number 1 in this example exacly like show method :
public function startreserve(Request $request,Property $property){
.
.
.
return view('users.properties.reserve')
->with('property',$property);
}
now when i pass $property its empty but i want to do it as the show method !!!
ok now for example i want to pass the id 1 property and make the link look like this :
http://localhost:8000/properties/startreserve/1
and here is my view code :
<form class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed"
action="/properties/startreserve" method="post">
{{ csrf_field() }}
#if ($errors->any())
<div class="panel panel-flat bg-danger">
<div class="panel-heading">
<h5 class="panel-title"></h5>
<div class="heading-elements">
<ul class="icons-list">
<li><a data-action="close"></a></li>
</ul>
</div>
</div>
<div class="panel-body">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
</div>
#endif
<div class="row">
#foreach($pdate as $index => $pdates)
<div id="checkboxes" class="col-lg-2 text-center">
<input type="checkbox" name="d[{{$index}}]"value="{{verta($pdates->date)->format('Y/m/d')}}-{{$pdates->price}}" id="d{{$index}}"/>
<label class="whatever mt-3" for="d{{$index}}"> {{verta($pdates->date)->format('Y/m/d')}}
<hr>
{{$pdates->price}}</label>
</div>
#endforeach
<div class="col-lg-12">
<input type="submit" value="send" class="btn btn-primary">
</div>
</div>
</form>
You need to define the id on the route itself, as the route you have is not accepting the id.
Route::post('/properties/startreserve/{property}','PropertyController#startreserve');
So using a post request, you should be passing the ID in your action, you are missing that here.
<form class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed"
action="/properties/startreserve/{{$property->id}}" method="post">
I have a filter functionality with pagination. Filter is working initially. When I click on pagination next button result is not showing based on filter.
eg: I have three countries in filter box. I chosen two then click on filter button then result is showing correct on first page but When I click on pagination next button all three countries result is showing not appending filter.
Thank you any help would be appreciated
Framework: laravel 5.5
Database: MongoDB
route.php
Route::match(['get', 'post'], '/search', 'SearchController#index')->name('search');
SearchController.php
public function index(SearchRequest $request)
{
$data = $request->all();
$cabin = Cabin::select('_id', 'name', 'country', 'region', 'interior', 'sleeping_place', 'height', 'other_details', 'interior')
->where('is_delete', 0)
->where('other_cabin', "0");
if(isset($request->cabinname)){
$cabin->where('name', $request->cabinname);
}
if(isset($request->country)){
$cabin->whereIn('country', $data['country']);
}
//dd($cabin->count());
if(isset($request->region)){
$cabin->whereIn('region', $data['region']);
}
$cabinSearchResult = $cabin->simplePaginate(5);
return view('searchResult', ['cabinSearchResult' => $cabinSearchResult]);
}
search.blade.php
<form action="{{ route('search') }}" method="POST" class="navbar-form navbar-left" id="search-nav-home">
{{ csrf_field() }}
<div class="form-group navbar-form navbar-left" id="prefetch">
<input type="text" class="form-control-home typeahead" name="cabinname" id="cabinname" placeholder="Search Cabin">
</div>
<ul class="nav navbar-nav" id="filter-home">
#if($services->country())
<li class="dropdown">
<!-- Dropdown in Filter -->
Country <span class="caret"></span>
<ul class="dropdown-menu dropdown-menu-home">
#foreach($services->country() as $land)
<li class="check-it-list-home"><input type="checkbox" class="check-it-home" name="country[]" value="{{ $land->name }}"> {{ $land->name }}</li>
#endforeach
</ul>
</li>
#endif
#if($services->regions())
<li class="dropdown">
Region<span class="caret"></span>
<ul class="dropdown-menu dropdown-menu-home drop-height">
#foreach($services->regions() as $region)
<li class="check-it-list-home"><input type="checkbox" name="region[]" value="{{ $region->name }}" class="check-it-home"> {{ $region->name }}
</li>
#endforeach
</ul>
</li>
#endif
</ul>
<div class="form-group navbar-form navbar-right" id="navbar-right-filter-home">
<button type="submit" class="btn btn-default-home btn-filter-home">Filter Cabins</button>
</div>
</form>
In the result View you may need to append the query link to the generated paginate link:
First in your controller, send the result of the search to the view e.g.:
....
return view('searchResult', ['cabinSearchResult' => $cabinSearchResult, 'next_query' => $data]);
Then in your View, use appends and link() method on $searchResult where you display the paginated link instead of only link() or render(), like this:
....
{{ $searchResult->appends($next_query)->links() }}
This should generate links with the query string that contains your old search query on all the pages generated.
Read more about pagination in Laravel Docs
This is my form tag
<form method="POST" action="{{ url("/post/{$article->id}/comment") }}">>
This is my route
Route::post('/post/{article}/comment', 'CommentController#store');
This is my commentcontroller method
public function store(Article $article)
{
$comment = $article->comment->create([
'body' => request('body'),
]);
return back();
}
show.blade.php
`#extends('master')
#section('content')
<!-- Example row of columns -->
<div class="container">
<h1> {{ $articles->title }} </h1>
<p> {{ $articles->body }} </p>
<hr></hr>
<div class="comment">
<ul class="list-group">
#foreach($articles->comments as $comment)
<li class="list-group-item">
<strong>
{{ $comment->created_at->diffForHumans()}} :
</strong>
{{ $comment->body }}
</li>
#endforeach
</ul>
</div>
<!-- Here is comment form -->
<hr>
<div class="card">
<div class="card-block">
<form method="POST" action="{{ url ("/post/{$article->id}/comment") }}">>
{{ csrf_field() }}
<div class="form-group">
<textarea name="body" placeholder="your comment here." class="form-control"> </textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Add Comment</button>
</div>
</form>
</div>
#include('partials.errors')
</div>
</div>
#endsection`
When I'm trying to add comment on article I'm getting an error like this:
> Undefined variable: article (View: C:\xampp7\htdocs\Lara\resources\views\article\show.blade.php)
Anything wrong in this? help me out. Thanks in advance
It seems you are not passing $article to view. You haven't included the code but you have somewhere something like this:
return view('article.show');
and instead you should have:
return view('article.show', compact('article'));
so finally your show method in controller should look something like this:
public function show(Article $article)
{
return view('article.show', compact('article'));
}
Its because you are calling your article $articles (plural) when in fact it is a single article.
in your controller change $articles to $article and then change it in the view where you have articles, for instance $articles->body. It will then be correct when you use it in the form action.
Within a Layout
#section('breadcrumbs', Breadcrumbs::render('messages'))
#section('content')
#include('layouts.breadcrumbs')
breadcrumbs.blade.php
<div class="fluid-container">
<div class="container">
<div class="row">
<div class="col-md-12">
#yield('breadcrumbs')
</div>
</div>
</div>
</div>
Standard BS3 view with DaveJamesMillar Breadcrumbs
#if ($breadcrumbs)
<ol class="breadcrumb">
#foreach ($breadcrumbs as $breadcrumb)
#if ($breadcrumb->url && !$breadcrumb->last)
<li>{{ $breadcrumb->title }}</li>
#else
<li class="active">{{ $breadcrumb->title }}</li>
#endif
#endforeach
</ol>
#endif
Appeared to be working fine until upgrading to L5.4, now rather than displaying the breadcrumbs it displays non-processed HTML
<ol class="breadcrumb"> <li>Home</li> <li> class="active">Messages</li></ol>
After reading the latest docs for davejamesmillar laravel-breadcrumbs with support for L5.4 https://media.readthedocs.org/pdf/laravel-breadcrumbs/latest/laravel-breadcrumbs.pdf with reference to 1.4.2 using Blade Sections nothing appears to have changed in the way this needs to be coded. Unsure why the HTML is not being processed to display as a link.
RAR, hours later! Appears Laravel 5.4 runs a htmlentities when injecting a variable into a #section
I changed
#section('breadcrumbs', Breadcrumbs::render('messages'))
to
#section('breadcrumbs') {!! Breadcrumbs::Render('messages') !!} #endsection
And the html is now being processed and displayed as it should.
I want to know what language can make my template being dynamic. Example HTML sturtcure
<div id="tabs">
<ul class="tabs">
<li>Header</li>
<li>Navigation</li>
<li>Layout & Colors</li>
<li>Optimization</li>
<li>Miscellaneous</li>
</ul>
<form method="post" action="options.php">
<div class="tab-container">
<div id="tabs-1" class="tab-content">Header</div>
<div id="tabs-2" class="tab-content">Navigation</div>
<div id="tabs-3" class="tab-content">Layout & Colors</div>
<div id="tabs-4" class="tab-content">Optimization</div>
<div id="tabs-5" class="tab-content">Miscellaneous</div>
</div>
</form>
</div>
I want the LI and DIV
<li>Header</li>
<div id="tabs-1" class="tab-content">Header</div>
Can be dynamic without write it one by one. How to do that?
jQuery Templates works best in this scenario.
Check the doc #:
http://api.jquery.com/jQuery.template/
I'd use Python, more specifically Flask. Here's a maybe-working template. I'm guessing your element's names are stored in a list returned by get_titles:
<div id="tabs">
<ul class="tabs">
{% for index in get_titles|length %}
<li>{{ titles[index] }}</li>
{% endfor %}
</ul>
<form method="post" action="options.php">
<div class="tab-container">
{% for index in titles|length %}
<div id="tabs-{{ index + 1 }}" class="tab-content">{{ titles[index] }}</div>
{% endfor %}
</div>
</form>
</div>
But then again, this might be a bit overkill.