跳至主要內容

Laravel Model::create or Model->save()

 

Asked 
Viewed 30k times
19

I'm wondering what approach should I use for storing data in the database;

First approach

$product = Product::create($request->all());

In my Product model I have my $filable array for mass assigment

Second approach

    $product = new Product();
    $product->title = $request->title;
    $product->category = $request->category;
    $product->save();

Is any of these two "Better solution"? What should I generally use?

Thank you for you advice

留言

此網誌的熱門文章

《Clean Code 2: Vue 3 檔案/資料夾結構》

[Laravel][ATOMIC] DB::transaction, DB::beginTransaction

[laravel 9] rename project