y have this Controller with GET vars:
localhost/ordersys/public/admin/orders?provid=220001&price=500
{!! Form::open(array('action' => array('Admin\OrdersController#filter'), 'role'=>'search', 'method' => 'GET')) !!}
{!! Form::text('provid', null, array('class' => 'typeahead form-group form-control', 'placeholder' => 'Search by Provid here...')) !!}
{!! Form::text('price', null, array('class' => 'typeahead form-group form-control', 'placeholder' => 'Price max ...')) !!}
{!! Form::submit('Search', array('class' => 'btn btn-default search-bar-btn')) !!}
{!! Form::close() !!}
$varprovid = Input::get('provid');
$varprice = Input::get('price');
$collection = DB::table('orders')
->where('cod_prov', $varprovid)
->where('price', '<', $varprice)
->paginate(15);
This work, but how can catch the Inputs Input::get('provid'), Input::get('price') from Form and filter Collection using Where clauses dynamically. I can build array and use foreach loop? Any idea please, thanks.
Related
I define a component for my forms :
/resources/views/components/form.blade.php
{!! Form::model($model, $form) !!}
{{ $slot }}
{!! Form::close() !!}
and in the edit blade file I write some codes like this :
#component('components.form',[
'model' => $user,
'form' => [
'route' => ['users.update', $user],
'method' => 'put',
'class' => 'col-sm-12'
]
])
{!! Form::text('username', null, ['class' => 'form-control']) !!}
#endcomponent
Unfortunately, the fields cannot fill with previous values.
But when I {{ dump($model) }} in /resources/views/components/form.blade.php the variable have a Object value.
What is the problem?
So, i have some categories. And in each category you can add posts.
But in form page for adding posts, how to get the value of that category i.e. of previous page?
This is my form:
<div class="container">
{!! Form::open(['action' => 'TopicController#store', 'method' => 'POST']) !!}
<div class="form-group">
{{ Form::label('title', 'Title') }}
{{ Form::text('title', '', ['class' => 'form-control', 'placeholder' => 'Title of the Post']) }}
</div>
<div class="form-group">
{{ Form::label('desc', 'Desc') }}
{{ Form::textarea('desc', '', ['class' => 'form-control', 'placeholder' => 'Description of the Post']) }}
</div>
{{ Form::submit('Submit', ['class' => 'btn btn-default']) }}
{!! Form::close() !!}
</div>
Link in category page to form:
Create New Post
Controller:
$this->validate($request, [
'title' => 'required',
'desc' => 'required',
])
$topic = new Topic;
$topic->topic_title = $request->input('title');
$topic->topic_body = $request->input('desc');
$topic->user_id = auth()->user()->id;
$topic->save();
return redirect('/')->with('Seccess', 'Topic Created');
show.blade.php contains link to this form page. But to get the id of the category page that is referring to this form??
You need to pass category_id into your link as route parameter:
Create New Post
Catch category_id in /topics/create/category_id route:
Route::post('/topics/create/{category}', 'TopicsController#create');
And then use it to create a hidden field in your form:
<div class="container">
{!! Form::open(['action' => 'TopicController#store', 'method' => 'POST']) !!}
{{ Form::hidden('category_id', $category_id) }}
...
</div>
And then in your controller:
...
$topic->category_id = $request->input('category_id');
$topic->user_id = auth()->user()->id;
$topic->save();
...
Am new in php laravel and am getting the following error when displaying a page that should be having a form
ErrorException in FormBuilder.php line 525: Undefined offset: 1 (View: E:\mysite\mysite\resources\views\predictions\create.blade.php)
Here is the form code:
#extends('layouts.master')
#section('content')
<h2>Create Predictions</h2>
{!! Form::open(array('route' => 'predictions.store')) !!}
<div class="form-group">
{!! Form::label('title')!!}
{!! Form::text('title',null, array('class' => 'form-control')) !!}
</div>
<div class="form-group">
{!! Form::label('body')!!}
{!! Form::textarea('body',null, array('class' => 'form-control', 'size' => '50*3')) !!}
</div>
{!! Form::token() !!}
{!! Form::submit(null, array('class' => 'btn btn-default')) !!}
{!! Form::close() !!}
Here is the formbuilder code with the exception:
protected function setQuickTextAreaSize($options)
{
$segments = explode('x', $options['size']);
return array_merge($options, ['cols' => $segments[0], 'rows' =>
$segments[1]]);
}
Thanks in advance
There is no size attribute for textarea input tag. Remove 'size' => '50*3' from below code
{!! Form::textarea('body',null, array('class' => 'form-control', 'size' => '50*3')) !!}
Use rows and cols attribute instead. Since I guess you're trying to set 3 rows and 50 columns as your textarea box size your code may like this:
{!! Form::textarea('body',null, array('class' => 'form-control', 'rows' => '3', 'cols' => '50')) !!}
My form.blade.php is sth like
<div class="form-group">
{!! Form::label('title', 'title :', ['class' => 'awesome']) !!}
{!! Form::text('product[title]', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('description', 'description : ', ['class' => 'awesome']) !!}
{!! Form::text('product[description]', null, ['class' => 'form-control']) !!}
<div id="phone" class="form-group">
{!! Form::label('reference_id1', 'reference_id1 : ', ['class' => 'awesome']) !!}
{!! Form::text('product[reference_id1]', null, ['class' => 'form- control']) !!}
</div>
<div class="form-group">
{!! Form::label('category_id', 'category_id : ', ['class' => 'awesome']) !!}
{!! Form::select('category[]', $categories,null, ['class' => 'form- control', 'multiple']) !!}
</div>
<div class="form-group">
{!! Form::label('color', 'color : ', ['class' => 'awesome']) !!}
{!! Form::text('feature[0][color]', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('height', 'height : ', ['class' => 'awesome']) !!}
{!! Form::text('feature[0][height]', null, ['class' => 'form-control']) !!}
</div> `
and my Edit.blade.php is like
{!! Form::model($product,['method' => 'PATCH', 'action' => ['ProductController#update',$product->id]]) !!}
#include('products.form', ['submitBtn' => 'submit'])
{!! Form::close() !!}
And this my ProductController.php#edit
public function edit($id)
{
$product = Product::with('feature')->findOrFail($id);
$categories = Category::pluck('title','id');
return view('products.edit')->withProduct($product)->withCategories($categories);
}
this is while when i wanna edit a product, the input requests are set empty!!
for instance when i go to http://myLarave/Public/product/2/edit the title and other inputs are empty :(
any suggestions?!
In your route.php or web.php depend to the version of your laravel, you can make the arg {id?}, for example:
Route::get('edit/{id?}', 'ProductController#edit');
and in the edit function you can initialize the variable $id=null or empty:
public function edit($id = null)
{
if($id != null){
$product = Product::with('feature')->findOrFail($id);
$categories = Category::pluck('title','id');
return view('products.edit')->withProduct($product)->withCategories($categories);
}
}
Ok, so I have a partial contact form in the layout, and I'm trying to get the inputted data to pass to the full contact view form instead of submitting request via clicking the submit button. In my partial, it has name, email, and phone input. I want the info to populate the appropriate input and the remaining inputs in the full contact form and the rest to be blank waiting for users to input them. Then naturally on submit it sends out. the full contact form is already working, I just need to get this partial on the layout to work. The problem is it's redirecting it to a view that's a get method. I myself don't like this idea, but it's for my job and this is what they want. I would preferr to not have to make another view. This is what i have so far
the layout form:
{!! Form::open(array('url' => 'contact_index')) !!}
<div class="form-group">
{!! Form::label('Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control', 'placeholder' => '', 'size' => '25']) !!}
</div>
<div class="form-group">
{!! Form::label('Email:') !!}
{!! Form::email('email', null, ['class' => 'form-control', 'placeholder' => '', 'size' => '25']) !!}
</div>
<div class="form-group">
{!! Form::label('Phone:') !!}
{!! Form::text('phone', null, ['class' => 'form-control', 'placeholder' => '', 'size' => '25']) !!}
</div>
<br/>
<div class="form_group">
{!! Form::submit('Submit', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
this is the controller it redirects to
public function Index()
{
$email = Input::get('email');
$name = Input::get('name');
$phone = Input::get('phone');
session_start();
$_SESSION['name'] = $name;
$_SESSION['email'] = $email;
$_SESSION['phone'] = $phone;
return View('contact_views.Index',compact('email','name','phone'));
}
This is the view of the full contact:
{!! Form::open(array('url' => 'Contact')) !!}
<div class="form-group">
{!! Form::label('Email:') !!}
{!! Form::email('email', null, ['class' => 'form-control',
'placeholder' => '', value =>'$_SESSION['email']', size' => '25']) !!}
</div>
<div class="form-group">
{!! Form::label('Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control', 'placeholder' => '',
value =>'$_SESSION['name']', 'size' => '25']) !!}
</div>
<div class="form-group">
{!! Form::label('Phone:') !!}
{!! Form::text('phone', null, ['class' => 'form-control', 'placeholder' => '',
value =>'$_SESSION['phone']', 'size' => '25']) !!}
</div>
<div class="form-group">
{!! Form::label('Subject:') !!}
{!! Form::text('subject', null, ['class' => 'form-control', 'placeholder' => '',
value =>'', 'size' => '25']) !!}
</div>
<div class="form-group">
{!! Form::label('Message:') !!}
{!! Form::textarea('message', null, ['class' => 'form-control', 'placeholder' => '',
value =>'', 'size' => '25x12']) !!}
</div>
<br/>
<div class="form_group">
{!! Form::submit('Submit', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
As of now this is the error I'm getting FatalErrorException in b6da938076cfb151c583150cb7d0dec6 line 51:
syntax error, unexpected 'email' (T_STRING), expecting ']' .
You have an extra single quote on the line next to the "size" variable
'placeholder' => '', value =>'$_SESSION['email']', size' => '25']) !!}