Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nitz25's avatar

CRUD

Hello, I am starting to make a project where I can create, read, edit and delete data from database. And I know that there's a lot of crud generator in github but I am confused and I want to make my own so that I can practice it. Is there anything changes in laravel 5.2? This is the command I know on how to store data..

public function store(Request $request)
    {
         $data=[
            'username'=>Input::get('username'),
            'name'=>Input::get('name'),
            'usertype'=>Input::get('usertype'),
            'password'=>Hash::make('password'),
               ];
    Model::create($data);
    }

Thanks

0 likes
8 replies
bobbybouwmann's avatar

@sohelamin Well that won't work.. He is hashing the password as well!

Well the laravel way would be creating a repository or maybe even a job. But you can simply do something like this

public function store()
{
    $request->merge([
        'password' => bcrypt($request->get('password')), // Helper function for Hash::make
    ]);

    Model::create($request->all());

    return redirect()->route('model.index');
}
2 likes
AddWebContribution's avatar

Use below given code for store data

public function store(Request $request)
{
   $data=array(
       'username'=>$request->username,
       'name'=>$request->name,
       'usertype'=>$request->usertype,
       'password'=>bcrypt($request->password),
   );

Model::create($data);
}
chandy's avatar

First, make sure you have a fillable or guarded property define for your model fields e.g

protected $guarded=[]; or protected $fillable=['model fields'];

then in your controller do this:

$request->request->password=bcrypt($request->password); Model::create(array_merge($request->all()));

Please or to participate in this conversation.