Route binding #408
              
                
                  
                  
                    Answered
                  
                  by
                    Oleksandr-Moik
                  
              
          
                  
                    
                      carlosvaldesweb
                    
                  
                
                  asked this question in
                Q&A
              
            -
| How can i use route binding? public function show(Blog $blog)
    {
        return new BlogResource($blog);
    }I'm getting My Blog model class Blog extends Model implements TranslatableContract
{
    use HasFactory;
    use SoftDeletes;
    use Translatable;
    protected $fillable = [
        'published',
        'scheduled_at',
    ];
    public $translatedAttributes = [
        'title',
        'content',
        'meta_description',
        'locale',
        'slug',
        'image',
    ];
    public function getRouteKeyName(): string
    {
        return 'slug';
    }
} | 
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            Oleksandr-Moik
          
      
      
        Apr 25, 2024 
      
    
    Replies: 1 comment
-
| You can override the default query for route binding, for example in my case it looks like     public function resolveRouteBindingQuery($query, $value, $field = null)
    {
        if (request()->routeIs('filament.*')) {
            return parent::resolveRouteBindingQuery($query, $value, $field);
        }
        return $query->whereTranslation('slug', $value);
    } | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
      Answer selected by
        Gummibeer
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
You can override the default query for route binding, for example in my case it looks like