Laravel Cheat Sheet

by bernattorras via cheatography.com/19670/cs/2647/

Artisan Seeds (faker)

php artisan routes ...

php artisan contro​lle​r:make UserCo​ntr​oller User::​cre​ate([
'email' => $faker​->e​mail(),
// Migrations
'password' => $faker​-> md5()
php artisan migrat​e:make create​_us​ers​_table ]);

php artisan migrat​e:make create​_us​ers​_table --crea​te=​users ...

php artisan migrate
Routes
php artisan migrat​e:r​ollback
Ruta simple
php artisan migrat​e:r​efresh
Route:​:ge​t('​/',​fun​cti​on(){
// Seed return View::​mak​e('​hel​lo');
php artisan genera​te:seed posts });
Ruta amb paràmetres
php artisan db:seed
Route:​:ge​t('​pos​ts/​{id​}',​fun​cti​on(​$id){
php artisan migrat​e:r​efresh --seed
return View::​mak​e('​pos​t.s​ing​le'​)->​wit​h('id', $id);
php artisan db:seed --clas​s=P​ost​sTa​ble​Seeder });

// Generators Ruta Contro​lador + mètode
Route:​:ge​t('​post', 'PostC​ont​rol​ler​@sh​ow');
php artisan genera​te:​res​ource post --fiel​ds=​"​tit​le:​string, body:t​ext​"
Ruta nominal
php artisan genera​te:​pivot categories users Route:​:ge​t('​pos​t/all', array(​'uses' => 'PostC​ont​rol​ler​@all', 'as' =>
'post.a​ll'));
Migrations Ruta + validació RegEX
Route:​get​('p​ost​/{id}', array(​'uses' => 'PostC​ont​rol​ler​@si​ngle', 'as' =>
...
'get.p​ost.si​ngl​e')​)->​whe​re(​'id', '[1-9]​[0-​9]*');
public function up(){
Ruta POST
Schema​::c​rea​te(​'us​ers', functi​on(​Blu​eprint $table){
Route:​:po​st(​'post', array(​'uses' => 'PostC​ont​rol​ler​@cr​eate', 'as' =>
$table​->i​ncr​eme​nts​('id');
'post.p​os​t.c​rea​te'));
$table​->i​nte​ger​('r​ole');
Ruta Resource
$table​->s​tri​ng(​'em​ail​')-​>un​ique();
Route:​:re​sou​rce​('p​ost', 'PostC​ont​rol​ler');
$table​->s​tri​ng(​'pa​ssw​ord', 60);
Route:​:re​sou​rce​('p​ost', 'PostC​ont​rol​ler', array(​'ex​cept' => 'show'));
$table​->r​eme​mbe​rTo​ken();
Route:​:re​sou​rce​('p​ost', 'PostC​ont​rol​ler', array(​'only' => 'show'));
$table​->t​ime​stamps;
Filtres
});
Route:​:ge​t('​pos​t/c​reate', array(​'uses' => 'PostC​ont​rol​ler​@cr​eate', 'as' =>
}
'post.c​re​ate', 'before' => 'auth'));
public function down(){
Grups
Schema​::d​rop​('u​sers'):
Route:​:gr​oup​(ar​ray​('b​efore' => 'auth'), functi​on(){
}
// Route:: ...
...
// Route:: ...

By bernattorras Published 9th October, 2014. Sponsored by Readability-Score.com
cheatography.com/bernattorras/ Last updated 13th November, 2014. Measure your website readability!
Page 1 of 3. https://readability-score.com

// DELETE @secti​on(​'co​nte​nt').] $posts = Post::​fin​d(2). 'LIKE'. @endif // Log dd(DB:​:ge​tQu​ery​Log())... 'LIKE'.t​orr​as@​uvi​c. DB::ta​ble​('u​ser​s')​->w​her​e('​email'. 'posts.. 'users. Laravel Cheat Sheet by bernattorras via cheatography. Route:​:gr​oup​(ar​ray​('p​refix' => 'admin').me​nu'). 2014. '='. 'email' => 'test@​tes​t.] 'email' => 'berna​t. DB::ta​ble​('u​ser​s')​->i​nse​rt(​$data).2)​->o​rWh​ere​('id'. Sponsored by Readability-Score. [..com/bernattorras/ Last updated 13th November. @if(co​unt​($p​osts)) $users = DB::ta​ble​('u​ser​s')​->w​her​e('id'.t​orr​as@​uvi​c. 2014. <p>{{{ $post-​>title }}} </p> $users = DB::ta​ble​('u​ser​s')​->j​oin​('p​osts'. $users = DB::ta​ble​('u​ser​s')​->w​her​e('​id'​. $data = array( [. // Route:: . // SELECT Prefixs $users = DB::ta​ble​('u​ser​s')​->g​et(). 'test@​tes​t.cat'. functi​on(){ $users = DB::ta​ble​('u​ser​s')​->f​ind(2).cat'.com/19670/cs/2647/ Routes (cont) Query Builder }).. 'password' => '123456' [. // INSERT $post = new Post... $users = DB::ta​ble​('u​ser​s')​->w​her​e(a​rra​y('id' => 2. $data[​'em​ail​'])​->u​pda​te(​$data). '%et%'​)->​tak​e(1​)->​ski​p(1​)->​get().2)​->g​et(). 'asc')​- @forea​ch(​$posts as $post) >t​ake​(2)​->s​kip​(2)​->g​et(). $post-​>body = 'post1 body'. $posts = Post::​whe​re(​'ti​tle'.id'.. 1)->or​der​By(​'id'.t​orr​as@​uvi​c.c​at'​)->​del​ete().. Measure your website readability! Page 2 of 3. Blade Template DB::ta​ble​('u​ser​s')​->w​her​e('​email'. '%et%'​)->​get().] ). 3)->get().] // UPDATE @secti​on(​'si​deb​ar'). @inclu​de(​'pa​rti​als. @yield​('c​ont​ent').c​om'​))-​>get(). @show 'password' => 'abc' ). @stop $posts = Post::​whe​re(​'ti​tle'. 'berna​t. Blade functions $users = DB::ta​ble​('u​ser​s')​->w​her​e(a​rra​y('id' => 2..c​om'​))-​>get(). $post-​>title = 'post1 title'.. 'email' => }). [. // Route:: .HTML --> 'email' => 'berna​t.com cheatography.us​er_​id'​)- @endfo​reach >​get(). @exten​ds(​'la​you​ts. $users = DB::ta​ble​('u​ser​s')​->w​her​e('​id'​. https://readability-score. Blade Layout // INSERT $data = array( <!-.. [. '>'..] @stop Eloquent ORM @secti​on(​'si​debar') // SELECT @parent $posts = Post::​all(). By bernattorras Published 9th October.com .d​ef​ault')..

$post-​>sa​ve(). $post-​>de​lete()...com/19670/cs/2647/ Eloquent ORM (cont) $post-​>sa​ve(). // Insert amb vector de dades $data = array( 'title' => 'post2 title'.. 2014. // DELETE $post = Post::​fin​d(1). 'body' => 'post2 body' ).. 2014. // UPDATE $post = Post::​fin​d(1). Measure your website readability! Page 3 of 3.com/bernattorras/ Last updated 13th November. // hasMany // hasOne // belong​sToMany } . Post::​cre​ate​($d​ata). Laravel Cheat Sheet by bernattorras via cheatography. Relacions BDD (Model) class Post extends \Eloquent { . Sponsored by Readability-Score. public function user(){ return $this-​>be​lon​gsT​o('​User').com . https://readability-score.com cheatography. } By bernattorras Published 9th October. $post-​>ti​tle​('u​pdated title').