return view('form')->with('path', $path);
Jun 12, 2018
3
Level 1
Passing string (path) from view to controller
I have a button that the user shall use to upload csv file. Then this csv is read in the controller and uploaded in a database.
This is my view:
<div class="upload-btn-wrapper">
<button class="btn"> Upload csv file </button>
<input type="file" name="myfile"/>
</div>
</form>
In my controller I just have the $path in the variable where the path to the file is stored:
public function read_xsl()
{
$path = '../data/blog-urls-gartenbau.csv';
if (($handle = fopen($path, "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$num = count($data);
for ($c=0; $c < $num; $c++)
{
$rawUrl = $data[$c];
$hashedUrl = sha1($data[$c]);
\DB::table('job_urls')->insert(
[
'job_id' => 1,
'url' => $rawUrl,
'hash' => $hashedUrl,
'created_at' => \Carbon\Carbon::now(), # \Datetime()
'updated_at' => \Carbon\Carbon::now(),
]);
}
}
fclose($handle);
}
return view('form');
}
Which is the best way to pass data from view to controller? Thanks for the help.
Please or to participate in this conversation.