CodeHint


Laravel (27 items)



    Route::resource('posts', 'postsController')

Create RESTful routes use on basic route name

  Edit
    Route::model('posts', 'App\Post')

Binds a model class to a resource name on controller

  Edit
    Route::get('name', 'action')

GET named route with specific action ('controller@action')

  Edit
php artisan make:model Post

Creates new model

  Edit
  php artisan make:request ...
Creates new request :
public function authorize(){ return true; }
public function rules (){ return []; }
  Edit
  Route Model Binding
Pass model to route and controller instead of id
routes.php
Route::get('posts/{post}', function($post){ return $post; }
RouteServiceProvider.php (in boot(Router $router))
$router->model('post', 'App\Post');
  Edit
  Command Bus
Para executar o command bus inclua o trait dentro do controller
use DispatchesCommands
E antes da declaração da classe
Illuminate\Foundation\Bus\DispatchesCommands
Para executar:
$data = [];
$this->dispatch(new PostCommand($this->post, $data));
  Edit
    str_contains($haystack, $needle)

Verifies if string (haystack) has specific term

  Edit
  Str::slug

Create slug based on string<br /> <code>$slug = Str::slug($post->headline)</code>

  Edit
    Schema::drop
/* Function to drop table on migration */

Schema::drop('posts');
  Edit
    Schema::create
/* Function to create table on migration */

Schema::create('posts', function(Blueprint $table){
   $table->increments('id');
   $table->timestamps();
});
  Edit
    Schema::table
/* Function to change table on migration */
Schema::table('posts', function(Blueprint $table){
   $table->string('name');
   $table->dropColumn('status');
});
  Edit
    Carbon\Carbon::now()

Returns Carbon object with now time

  Edit
  abort(404)

Generate error page

  Edit
    Post::findOrFail($id)

Find post or fail

  Edit
    Post::latest("id")->get()

Same as Post::orderBy("id", "desc");

  Edit
    Post::oldest("id")->get()

Same as Post::orderBy("id", "asc");

  Edit
    dd($posts)

Die and dump variable. Nothing more to say

  Edit
php artisan make:request PostRequest
/* Create custom request class */
public function authorize(){ 
   return true; 
}
public function rules (){ 
   return []; 
}
  Edit
    Form::input('date', 'published_at', date('Y-m-d'), [])

Date input type using Form

  Edit
    @include('posts._form', ['submit' => 'Update post'])

Include partial inside view and pass arguments to it

  Edit
  Mutators
protected $fillable = ['name'];
public function setNameAttribute($name){
   $this->attributes['name'] = $name . $postname;
}
  Edit
    Auth::user()

Returns authenticated user

  Edit
    Auth::user()->posts()->save($post)

Save new post using user_id from the authenticated user

  Edit
    Auth::guest()

Verify if user is a guest

  Edit
    Auth::check()

Verify if user is logged

  Edit
php artisan serve

Serve the application now ready to receive requests though php

  Edit