Controller:
public function store(StoreSongRequest $request)
{
dd($request->get('song'));die;
}
create.blade.php
{!! Form::open(array('route' => 'songs.store', 'class' => 'form', 'novalidate' => 'novalidate', 'files' => true)) !!}
<div class="form-group">
{!! Form::label('Name') !!}
{!! Form::text('name') !!}
</div>
<div class="form-group">
{!! Form::label('Upload') !!}
{!! Form::file('song') !!}
</div>
<div class="form-group">
{!! Form::submit('Upload', array('class' => 'btn btn-primary')) !!}
</div>
{!! Form::close() !!}
When i submit i appear error:
TokenMismatchException in VerifyCsrfToken.php line 46:
I was comment out 'app\Http\Middleware\VerifyCsrfToken' in kernel.php file but still the same.
The issue is that post_max_size was low $_POST. Increasing post_max_size in php.ini solved the issue.
Related
I am having trouble updating my data in Laravel and this is giving me headache. Every time i clicked on the update button error occurs.
Below is the error:
"Route [admin/update] not defined. (View: C:\xampp\htdocs\Tailor\core\resources\views\expensesCat\edit.blade.php)"
here is the edit.blade
<div class="portlet light bordered">
<h3 class="page-title">Expenses Categories</h3>
{!! Form::model($expenses_category, ['method' => 'POST', 'route' => ['admin/update', $expenses_category->id]]) !!}
<div class="panel panel-default">
<div class="panel-heading">
Edit
</div>
<div class="panel-body">
<div class="row">
<div class="col-xs-12 form-group">
<input name="order_create_by" type="hidden" value="{{ Auth::user()->id }}">
{!! Form::label('name', 'Name*', ['class' => 'control-label']) !!}
{!! Form::text('name', old('name'), ['class' => 'form-control', 'placeholder' => '']) !!}
<p class="help-block"></p>
#if($errors->has('name'))
<p class="help-block">
{{ $errors->first('name') }}
</p>
#endif
</div>
</div>
</div>
</div>
The web.php
Route::post('/update/{id}', 'ExpensesCategoriesController#updateCat');
The ExpensesCategoriesController
public function updateCat(UpdateExpensesCategoriesRequest $request, $id)
{
$expenses_category = ExpensesCategory::findOrFail($id);
$expenses_category->update($request->all());
return redirect('admin/expenses_categories');
}
Use url in your form -
{!! Form::model($expenses_category, ['method' => 'POST', 'url' =>'admin/update/'.$expenses_category->id]) !!}
You're trying to use the route by its name, but you didn't name it. So, change it to:
'route' => ['admin.update', ....
And name the route:
Route::post('/update/{id}', 'ExpensesCategoriesController#updateCat')->name('admin.update');
Or:
Route::post('/update/{id}', ['as' => 'admin.update', 'uses' => 'ExpensesCategoriesController#updateCat']);
I want make search by parameters. But it shows i have mixing GET and POST methods. (Error message: MethodNotAllowedHttpException
No message). Blade form by default have POST. i changed to GET. Route have GET method. Maybe you can see what i am doing wrong. This is my VIEW:
{!! Form::open([ 'action' => ['HomePageController#index', 'method' => 'get']]) !!}
<div class="container">
<div class="col-xs-2 form-inline">
{!! Form::label('city_id', trans('quickadmin.companies.fields.city').'', ['class' => 'control-label']) !!}
{!! Form::select('city_id', $cities, old('city_id'), ['class' => 'form-control select2') !!}
</div>
<div class="col-xs-3 form-inline">
{!! Form::label('categories', trans('quickadmin.companies.fields.categories').'', ['class' => 'control-label']) !!}
{!! Form::select('categories', $categories, old('categories'), ['class' => 'form-control select2']) !!}
</div>
<div class="col-xs-3 form-inline">
{!! Form::label('search', trans('quickadmin.companies.fields.name').'', ['class' => 'control-label']) !!}
{!! Form::text('search', old('search'), ['class' => 'form-control', 'placeholder' => 'Search']) !!}
</div>
<div class="form-inline">
<div class="col-xs-2">
<button type="submit"
class="btn btn-primary">
Search
</button>
</div>
</div>
</div>
{!! Form::close() !!}
My controller:
public function index( Request $request)
{
$cities = \App\City::get()->pluck('name', 'id')->prepend(trans('quickadmin.qa_please_select'), '');
$categories = \App\Category::get()->pluck('name', 'id')->prepend(trans('quickadmin.qa_please_select'), '');
$name = $request->input('city_id');
$companies = \App\Company::All()->where('city_id', '=', $name);
return view('table', compact('companies', $companies, 'cities', $cities, 'categories', $categories));
My route:
Route::get('/', 'HomePageController#index');
Thank you for your help.
There is a problem in the form open, try it like this :
{!! Form::open([ 'action' => 'HomePageController#index', 'method' => 'get']) !!}
Hello I'm new to laravel 5.2 and going through some lessons.
For some reason form model binding is not working for me.
{!! Form::model($post, ['method'=>'PATCH', 'action'=> ['PostController#update', $post->id]]) !!}
I received data in $post because I'm using a workaround like this:
{!! Form::text('title', "$post->title" ,['class'=> 'form-control']) !!}
And that is showing my data.
Controller:
namespace App\Http\Controllers;
use App\Post;
use Illuminate\Http\Request;
use App\Http\Requests;
class PostController extends Controller{
public function update(Request $request, $id){
$post =Post::findOrfail($id);
$post->update($request->all());
return redirect('/posts');
}
}
create.blade.php view:
#section('content')
<h1>Create Post</h1>
{!! Form::open(['method'=>'POST', 'action'=>'PostController#store']) !!}
<!-- Title Form Input -->
<div class="form-group">
{!! Form::label('title', 'Title:') !!}
{!! Form::text('title', 'null', ['class'=> 'form-control']) !!}
</div>
<!-- Form Input -->
<div class="form-group">
{!! Form::submit('Create Post', ['class'=> 'btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
#endsection
You shouldn't be quoting the value for null in your input:
{!! Form::text('title', 'null', ['class'=> 'form-control']) !!}
should be
{!! Form::text('title', null, ['class'=> 'form-control']) !!}
Ok, try adding the body of the form into a partial called posts/partials/form.blade.phpand include it between the form open / model and form close tags.
Example:
posts/partials/form.blade.php
<!-- Title Form Input -->
<div class="form-group">
{!! Form::label('title', 'Title:') !!}
{!! Form::text('title', 'null', ['class'=> 'form-control']) !!}
</div>
<!-- Form Input -->
<div class="form-group">
{!! Form::submit($formButtonText, ['class'=> 'btn-primary form-control']) !!}
</div>
posts/create.blade.php
{!! Form::open(['method'=>'POST', 'action'=>'PostController#store']) !!}
#include('posts.partials.form', [
'formSubmitButtonText' => 'Create Post'
])
{!! Form::close() !!}
posts/edit.blade.php
{!! Form::model($post, ['method'=>'PATCH', 'action'=> ['PostController#update', $post->id]]) !!}
#include('posts.partials.form', [
'formSubmitButtonText' => 'Update Post'
])
{!! Form::close() !!}
I am trying to create simple form with post. But when i submit my form i get this error - MethodNotAllowedHttpException in RouteCollection.php line 219:
My route file:
Route::get('articles', 'ArticlesController#index');
Route::get('articles/create', 'ArticlesController#create');
Route::get('articles/{id}', 'ArticlesController#show');
Route::post('articles', 'ArticlesController#store');
Form:
{!! Form::open(['url' => 'articles', 'method' => 'post']) !!}
<div class="form-group">
{!! Form::label('title', 'Title:') !!}
{!! Form::text('title', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('body', 'Body:') !!}
{!! Form::textarea('body', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit('Add article', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
Controller class:
public function store(Request $request) {
$input = $request->all();
return $input;
}
Thanks for your attention. I dont get where is the problem.
Found answer. Just type php artisan route:clear in terminal.
You have the same url both in Route::get('articles', 'ArticlesController#index'); and Route::post('articles', 'ArticlesController#store');
Use action() instead of url can solve this problem. EX:
{!! Form::open(['action' => 'ArticlesController#store', 'method' => 'post']) !!}
Change the route: Route::get('articles', 'ArticlesController#index'); to Route::post('articles', 'ArticlesController#index');
I'm trying to include two sub-views ( 'login' and 'register' ) in the 'home' view which is like this:
#extends('master')
#section('content')
#include('auth.login')
<hr>
#include('auth.register')
#endsection
And the 'login' and 'register' views:
//register.blade.php
#extends('master')
#section('content')
{!! Form::open() !!}
<div class="form-group">
{!! Form::label('email', 'Email Address') !!}
{!! Form::email('email', null,
['class' => 'form-control',
'placeholder' => 'Email Address',
'required' => true]) !!}
</div>
<div class="form-group">
{!! Form::label('password', 'Password') !!}
{!! Form::password('password',
['class' => 'form-control',
'placeholder' => 'Password',
'required' => true]) !!}
</div>
<div class="checkbox">
<label>
{!! Form::checkbox('remember', null, []) !!}
Remeber Me
</label>
</div>
{!! Form::submit('Login', ['class' => 'btn btn btn-primary']) !!}
{!! Form::close() !!}
#endsection
//login.blade.php
#extends('master')
#section('content')
{!! Form::open() !!}
<div class="form-group">
{!! Form::label('email', 'Email Address') !!}
{!! Form::email('email', null,
['class' => 'form-control',
'placeholder' => 'Email Address',
'required' => true]) !!}
</div>
<div class="form-group">
{!! Form::label('password', 'Password') !!}
{!! Form::password('password',
['class' => 'form-control',
'placeholder' => 'Password',
'required' => true]) !!}
</div>
<div class="checkbox">
<label>
{!! Form::checkbox('remember', null, []) !!}
Remeber Me
</label>
</div>
{!! Form::submit('Login', ['class' => 'btn btn btn-primary']) !!}
{!! Form::close() !!}
#endsection
I've tried removing the master extension from the sub-views but it didn't work. Only one sub-view is being rendered. I can't figure out, why that's happening?
main.blade.php
#extends('master')
#section('content')
#include('auth.login')
<hr>
#include('auth.register')
#endsection
For the sub views you have to remove the #extends('master'). Then you have two options I can think of.
You can add the #parent directive.
register.blade.php
#section('content')
{!! Form::open() !!}
...
{!! Form::submit('Login', ['class' => 'btn btn btn-primary']) !!}
{!! Form::close() !!}
#parent
#endsection
login.blade.php
#section('content')
{!! Form::open() !!}
...
{!! Form::close() !!}
#parent
#endsection
or remove the sections.
register.blade.php
{!! Form::open() !!}
...
{!! Form::submit('Login', ['class' => 'btn btn btn-primary']) !!}
{!! Form::close() !!}
login.blade.php
{!! Form::open() !!}
...
{!! Form::close() !!}
See this similar question.
Updated per comments
If you need to access the pages separately you could extract the form code into partials and include them where needed.
main.blade.php
#extends('master')
#section('content')
#include('auth.partials.login')
<hr>
#include('auth.partials.register')
#endsection
Setup you stand alone pages.
auth/register.blade.php
#section('content')
#include('auth.partials.register')
#endsection
auth/login.blade.php
#section('content')
#include('auth.partials.login')
#endsection
Setup your partials
auth/partials/register.blade.php
{!! Form::open() !!}
...
{!! Form::submit('Login', ['class' => 'btn btn btn-primary']) !!}
{!! Form::close() !!}
auth/partials/login.blade.php
{!! Form::open() !!}
...
{!! Form::close() !!}