honeyBear
1 month ago
343
16
Laravel

Refactoring my store() method

Posted 1 month ago by honeyBear

How do I refactor the image upload code into a simpler one like using the Class:create([ ]); Any ideas on how should I approach this?

Post::create([
        'title' => request('title'),
        'description' => request('description'),
        'prize' => request('prize'),
        'location' => request('location'),
        'image' => request('image')
    ]);
    
    /**$post = new Post();
    $post->title = $request->input('title');
    $post->description = $request->input('description');
    $post->prize = $request->input('prize');
    $post->location = $request->input('location');
    $post->image = $fileNameToStore;
    $post->save();*/

Please sign in or create an account to participate in this conversation.