laravel 5.4 save data to database

Updated at 31-Aug-2021, By samar

laravel 5.4 save data to database

With this article, we’ll look at some examples of how to address the "laravel 5.4 save data to database" problem.

You can save data to database in laravel 5.4 using create() method and insert() method on query builder.
  • Save record using create method in Laravel

    //Create method to save record in users table
    //You can use code inside of controller's method
    $user = User::create([
        'name' => 'Kayla',
        'email' => '[email protected]',
        'password' => Hash::make('secret')
    return $user;
    //Import user model after namespace in controller
    //Import user model in laravel 8
    use App\Models\User;
    //Import user model in laravel version < 8
    use App\User;
    {"name":"Kayla","email":"[email protected]","updated_at":"2021-08-31T08:24:43.000000Z","created_at":"2021-08-31T08:24:43.000000Z","id":16}

    You can create record in table using create method. Create method returns the object of created record if query executed successfully.

Back to code snippet queries related laravel