R
R
Roman2019-03-02 13:49:26
Laravel
Roman, 2019-03-02 13:49:26

Why does $model->save() not work on the same input data, but Model::create() does?

Hello.
Why does it work like this:

public function store(Ticket $ticket, Request $request)
    {						
      //$ticket->save($request->all());
      
      Ticket::create($request->all());
      
      return redirect()->route('tickets.main')
      ->with('success','Ваш запрос в службу поддержки зарегистрирован!');
    }

and if you use save instead of create, then it creates a record in the database, but does not fill in the fields?
Is this some kind of Laravel bug or is it some kind of nuance? :)
Here is a piece of the form:
<form class="form" action="{{ route('tickets.store') }}" method="POST">
  @csrf
  @method('POST')

What's in the salt?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Arutyunov, 2019-03-02
@procode

Set up in the model $fillable? Also, the method save()can't take parameters like you do. Must be called $model->fill($data)->save();.
https://laravel.com/docs/5.7/eloquent#inserting-an...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question