vendredi 2 mars 2018

Call to undefined method create() error

I want to save my images with using save_image() function in media model..

Here is my media model;

class Media extends Model
{
public function save_image($file)
    {
        $realname = str_slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));
        $extension = $file->getClientOriginalExtension();
        $new_name = str_slug($realname) . "-" . time() . "." . $extension;
        $file->move(public_path('uploads'), $new_name);

        $image = DB::create([
            'image' => $new_name,
            'image_path' => "uploads/" . $new_name,
            'image_alt_name' => $realname
        ]);
        return $image;
    }
}

Are we have to say DB::table('media') at the first ? I mean, we are already on media model, is that necesary ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire