Answer the question
In order to leave comments, you need to log in
How to upload photos to database in Laravel?
Guys please help me, I don’t know what the problem is, it just doesn’t want to load into the database!
here is the controller upload code
public function store(Request $request)
{
$this->validate($request, [
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$article = new Carouseleinfos();
if ($request->hasFile('images')) {
$dir = public_path('/images/carousele');
$extension = strtolower($request->file('images')->getClientOriginalExtension()); // get image extension
$fileName = str_random() . '.' . $extension; // rename image
$request->file('images')->move($dir, $fileName);
$image->images = $fileName;
}
$article->text1 = $request->get('text1');
$article->text2 = $request->get('text2');
$article->images = str_slug($request->get('images'));
$article->textbutton = $request->get('textbutton');
$article->linkbutton = $request->get('linkbutton');
$article->save();
return view('crud_4/index');
}
}
Answer the question
In order to leave comments, you need to log in
public function store(Request $request) {
$this->validate($request, [
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$article = new Carouseleinfos();
if ($request->hasFile('images')) {
$dir = public_path('/images/carousele');
$extension = strtolower($request->file('images')->getClientOriginalExtension()); // get image extension
$fileName = str_random() . '.' . $extension; // rename image
$path_image = $dir . $fileName;
$request->file('images')->move($dir, $fileName);
$image->images = $fileName;
}
$article->text1 = $request->get('text1');
$article->text2 = $request->get('text2');
$article->images = str_slug($request->get('images')); // возможно тут сохранить путь к файлу $path_image
$article->textbutton = $request->get('textbutton');
$article->linkbutton = $request->get('linkbutton');
$article->save();
return view('crud_4/index');
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question