This specific content was written 12 years ago.
Please keep this in mind as it may be outdated and not adhering to best-practices.
Here are some tips you might find handy when you think you have done everything according to the tutorials!
In formrequests to authorise access only for registered/signed users we add
use Auth;
public function authorize()
{
if ( !Auth::check() )
return false;
return true;
}
Get user id in view files and controllers:
{{ Auth::user()->id }}
In controllers do not forget to include:
use Auth;
In controllers we always include the models we use and the formrequests we use:
use appname\Model1;
use appname\Model2;
use appname\Model3;
use Auth;
use appname\Http\Requests\ItemFormRequest;
In every model do not forget to declare which columns/fields will be accessible!
protected $fillable = ['column1', 'column2']
Display errors in view files with forms
@if(count($errors) > 0)
<ul class="alert alert-danger">
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
@endif
Change application name:
php artisan app:name myapp //create unique namespace!
You can declare all routes in route.php
Route::resource('item', 'ItemController');
For forms and strings which contain code that you do not want to be character escaped use:
{!! !!} instead of {{{ }}}
Mar 17 2015
Laravel 5 TIPS For Beginners!
Here are some tips you might find handy when you think you have done everything according to the tutorials!
In formrequests to authorise access only for registered/signed users we add
use Auth; public function authorize() { if ( !Auth::check() ) return false; return true; }Get user id in view files and controllers:
{{ Auth::user()->id }}In controllers do not forget to include:
In controllers we always include the models we use and the formrequests we use:
In every model do not forget to declare which columns/fields will be accessible!
Display errors in view files with forms
@if(count($errors) > 0) <ul class="alert alert-danger"> @foreach($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> @endifChange application name:
You can declare all routes in route.php
Route::resource('item', 'ItemController');For forms and strings which contain code that you do not want to be character escaped use:
{!! !!} instead of {{{ }}}Polyvios Damianakis
Biography to be completed
More Posts - Website
Follow Me:
Related posts:
By Polyvios Damianakis • PHP 0 • Tags: laravel 5, tips