Muhammad Arslan Muhammad Arslan - 10 months ago 39
MySQL Question

Failed to save file name in database in laravel

this is my addData method in UploadController

public function addData(Request $request)
$this->validate($request, [
'name' => 'required|min:1',
'email' => 'required|min:2',

$file = array('file' => Input::file('file'));
$rules = array('file' => 'required|mimes:jpg,png,jpeg');
$validator = Validator::make($file, $rules);

if ($validator->fails()) {
echo 'Not allowed!!';
if (Input::file('file')->isValid()) {
$destinationPath = 'uploads';
$name = Input::get('name');
$email = Input::get('email');
$extension = Input::file('file')->getClientOriginalExtension();
$fileName = Input::file('file')->getClientOriginalName();
$displayImage = Input::file('file')->move($destinationPath, $fileName);
$user = Profile::create([
'name' => $name,
'email' => $email,
'file_name' => $fileName,


echo 'Upload Succesfully <br>';

else {
Session::flash('error', 'uploaded file is not valid');
return Redirect::to('upload');
echo 'Nothing to upload';



this is working fine but when i change to this it save name and email but not file name what is the problem with this i am failed to find out problem

Profile::create($request->all(['file_name' => $fileName]));

it is possible that it take everything automatically with filename or not with
$request->all() function any other solution if you have for me or t is necessary to write every field name ?


Try to do it like this:

$request['file_name'] = $fileName;