Search
 
SCRIPT & CODE EXAMPLE
 

PHP

explicit route model binding in laravel

// In RouteServiceProvider
 public function boot()
    {
   		//don't forget import model at the top
        Route::model('unique_key', Blog::class);
        Route::bind('unique_key', function ($value) {
            return Blog::findOrFail($value);
           //return Blog::where('something', $value)->firstOrFail();
        });
   
   //default laravel codes
 }
Comment

laravel route model binding

Route::get('posts/{post:slug}', function(Post $post) {
    return view('post', [
        'post' => $post
    ]);
});
Comment

laravel model bind with route in model

/**
 * Retrieve the model for a bound value.
 *
 * @param  mixed  $value
 * @param  string|null  $field
 * @return IlluminateDatabaseEloquentModel|null
 */
public function resolveRouteBinding($value, $field = null)
{
    return $this->where('name', $value)->firstOrFail();
}
Comment

PREVIOUS NEXT
Code Example
Php :: $wpdb foreach 
Php :: php access multidimensional array by string 
Php :: php add number to the existing name 
Php :: change apply coupon text woocommerce 
Php :: google recaptcha varification in php codeigniter 
Php :: install php7 
Php :: overloading and overriding in php 
Php :: php dump to page 
Php :: php enablem mod 
Php :: curl failed laravel centos 
Php :: The Process class relies on proc_open, which is not available on your PHP installation cpanel 
Php :: update to php 7.4 
Php :: pagination using ajax 
Php :: routing with php 
Php :: php sms sending script 
Php :: laravel "query()-find" 
Php :: Declare A PHP Array 
Php :: taxonomy-{taxonomy-slug}.php 
Php :: unravel_index numpy 
Php :: php regex named groups 
Php :: trim php 
Php :: doctrine where 
Php :: php delete file 
Php :: php glue strings 
Php :: wordpress basic auth 
Php :: https://ubuntu.com/tutorials/install-and-configure-wordpress#3-install-wordpress 
Php :: laravel find 
Php :: how to develop package beside laravel project 
Php :: laravel lumen 
Php :: Custom search form 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =