Reputation: 213
I guys I read the documentation for do a upload file in laravel... But I don't understand more it (I'm beginner) It's my image.blade.php
{{Form::open(['url'=>'administrator/store ', 'files' => true])}}
{!!Form::file('image') !! }
{!! Form::submit('next')!!}
{{Form::close()}}
Administrator Controller
use Storage;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
public function store(Request $request) {
Storage::put($request->image, 'test') ;
}
I don't understand what I will put into the function..... Help me pls... Greetings!
Upvotes: 3
Views: 12928
Reputation: 13549
\Illuminate\Http\Request::file()
is what you have when you're uploading files.
This is just a instance of \Symfony\Component\HttpFoundation\File\UploadedFile class so you can move file to destination/storage what you want, something like that:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class MainController extends Controller
{
public function upload(Request $request)
{
/**
* @var \Symfony\Component\HttpFoundation\File\UploadedFile
*/
$uploadedFile = $request->file('image');
if ($uploadedFile->isValid()) {
$uploadedFile->move(destinationPath, $fileName);
}
}
}
Aso, you've been used \Illuminate\Filesystem\Filesystem::put()
in a wrong way. Below is like that method is implemented:
/**
* Write the contents of a file.
*
* @param string $path
* @param string $contents
* @param bool $lock
* @return int
*/
public function put($path, $contents, $lock = false)
{
return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
}
Upvotes: 5