F
F
FlooDwm2018-06-03 22:57:44
Laravel
FlooDwm, 2018-06-03 22:57:44

Request in laravel doesn't form slug field?

in the model

public function setSlugAttribute($value){
        $this->attributes['slug'] = Str::slug($this->title,"-");
    }

In the controller
public function store(Request $request)
    { 
        dd($request->all());
    }

At the exit:
array:5 [▼
  "title" => "Second"
  "published" => "1"
  "slug" => null
  "parent_id" => "0"
]

The question is why slug = null? Although if you register saving in the database in the model,
Category::create($request->all());
then everything is fine. The slug is formed as it should.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victor, 2018-06-03
@FlooDwm

The mutator only works when you set a model property and Request has nothing to do with it.

Y
Yan-s, 2018-06-03
@Yan-s

Request field in laravel is not formed by mutators?

No.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question