Show your code, I only see methods here...
Jan 27, 2016
18
Level 5
call to member function move() on a non-object larvel 5.2?
in my controller i try to upload files but when i use this methods same error i will get
isValid();
move($destinationPath);
getClintoriginalNmae();
do i need to install for laravel 5.2 im totally confuse.
Symfony\Component\HttpFoundation\File\UploadedFile;
this is my controller function
public function store(Request $request)
{
$this->validate($request, $this->rules);
$input = $request->all();
$file = $request->file('file');
$charge = $request->get('charge');
$date = $request->get('date');
$job = $request->get('job_id');
$id = \Auth::id();
$current_id = DB::table('charges')->max('invoice_no');
$data = array();
foreach ($charge as $key=>$value){
$data[] = [
'date' => $date,
'charge'=>$value,
'job_id'=>$job,
'user_id'=>$id,
'amount'=>$input['amount'][$key],
'category'=>$input['category'][$key],
'file'=>$value.$file[$key],
'invoice_no' => $current_id + 1,
];
}
;
dd($data);
//$des = storage_path().'/assets';
// $request->file('file')->move($des);
// DB::table('charges')->insert($data);
//Redirect::route('charges.index')->with('message', 'Charges created.');
}
this output is
array:2 [▼
0 => array:8 [▼
"date" => "2016-01-28"
"charge" => "ce"
"job_id" => "2"
"user_id" => 1
"amount" => "100"
"category" => "cat1"
"file" => "ceH:\xampp\tmp\phpA32A.tmp"
"invoice_no" => 16
]
1 => array:8 [▼
"date" => "2016-01-28"
"charge" => "se"
"job_id" => "2"
"user_id" => 1
"amount" => "200"
"category" => "120"
"file" => "seH:\xampp\tmp\phpA32B.tmp"
"invoice_no" => 16
]
]
i have to insert real name of the document and i want display on my view how can i ???? where to use and how ????
getClientOriginalExtension();
base_path() . '/assets/',
Level 12
@Hamelraj Ok, had some sleep, try this
public function store(Request $request)
{
// validate input
$this->validate($request, $this->rules);
// set destination path
$uploadDestinationPath = base_path() . '/assets/files/';
// get input
$input = $request->all();
$charge = $request->get('charge');
$date = $request->get('date');
$job = $request->get('job_id');
$id = \Auth::id();
$current_id = DB::table('charges')->max('invoice_no');
// make sure a file has been included
if ($request->hasFile('file')) {
// this form uploads multiple files
foreach ($request->file('file') as $fileKey => $fileObject ){
// make sure each file is valid
if ($fileObject->isValid()) {
// make destination file name
$destinationFileName = $job . '_' . $id . '_' . ($current_id + 1) . '.' . $fileObject->getClientOriginalExtension();
// move the file from tmp to the destination path
$fileObject->move($uploadDestinationPath, $destinationFileName);
// save the the destination filename
$dbFilenames[$fileKey] = $uploadDestinationPath . '/' . $destinationFileName;
}
}
} else {
// no files to include
//TODO:: handle error for no files uploaded (if not already covered in the $this->validate)
// set dbFilenames to empty array
$dbFilenames[] = '';
}
// make array for database
$data = array();
foreach ($charge as $key=>$value){
$data[] = [
'date' => $date,
'charge'=>$value,
'job_id'=>$job,
'user_id'=>$id,
'amount'=>$input['amount'][$key],
'category'=>$input['category'][$key],
'file'=> (isset($dbFilenames[$key])?$dbFilenames[$key]:''),
// if file with key does not exist (may not happen, if part of $this->validate), then save it or save empty
'invoice_no' => $current_id + 1,
];
}
;
// save the data
DB::table('charges')->insert($data);
// redirect
Redirect::route('charges.index')->with('message', 'Charges created.');
}
Please or to participate in this conversation.