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 ?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2GYLrXi
via IFTTT
Aucun commentaire:
Enregistrer un commentaire