Buenas tardes compañeros.
Estoy intentando guardar una imagen y me tira el siguiente error
League\Flysystem\Local\LocalFilesystemAdapter::__construct():
Argument #1 ($location) must be of type string, null given, called in C:\laragon\www\puntodeventa\vendor\laravel\framework\src\
Illuminate\Filesystem\FilesystemManager.php on line 183
¿Como lo estoy guardando? Pues hice una función en el Controlador base
Controller:
?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Str;
use Image, Config;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function postFileUpload($field, $request, $thumbnails = null)
{
$path = date('Y/m/d');
$original_name = $request->file($field)->getClientOriginalName();
$final_name = Str::slug($request->file($field)->getClientOriginalName() . '_' . time()) . '.' . trim($request->file($field)->getClientOriginalExtension());
if ($request->$field->storeAs($path, $final_name, 'uploads')):
$data = json_encode(['upload' => 'success', 'path' => $path, 'original_name' => $original_name, 'final_name' => $final_name]);
else:
$data = ['upload' => 'error'];
endif;
if ($thumbnails):
$file_path = Config::get('filesystems.disks.uploads.root') . '/' . $path . '/' . $final_name;
foreach ($thumbnails as $thumbnail):
$img = Image::make($file_path)->orientate();
$img->fit($thumbnail[0], $thumbnail[1], function ($constraint) {
$constraint->aspectRatio();
});
$img->save(Config::get('filesystems.disks.uploads.root') . '/' . $path . '/' . $thumbnail[2] . '_' . $final_name, 75);
endforeach;
endif;
return $data;
}
public function getFileDelete($disk, $file, $thumbnails = null)
{
$end_file = json_decode($file, true);
$file_path = Config::get('filesystems.disks.' . $disk . '.root') . '/' . $end_file['path'] . '/' . $end_file['final_name'];
if (file_exists($file_path)):
unlink($file_path);
if ($thumbnails):
foreach ($thumbnails as $thumbnail):
$thumbnail_path = Config::get('filesystems.disks.' . $disk . '.root') . '/' . $end_file['path'] . '/' . $thumbnail . '_' . $end_file['final_name'];
if (file_exists($thumbnail_path)):
unlink($thumbnail_path);
endif;
endforeach;
endif;
endif;
}
}
ProductController
public function store(StoreProductRequest $request)
{
$product = Product::create($request->all()+
[
'image' => $this->postFileUpload('image', $request, [[256,256,'256x256']]),
]);
return redirect()->route('product.index');
}
filesystems
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'throw' => false,
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
'uploads' => [
'driver' => 'local',
'root' => config('puntodeventa.server_uploads_paths'),
'visibility' => 'public',
],
'uploads_user' => [
'driver' => 'local',
'root' => config('puntodeventa.server_uploads_user_paths'),
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
],
],
puntodeventa
<?php
return [
'server_uploads_paths' => 'C:\laragon\www\puntodeventa\public\uploads',
'server_uploads_user_paths' => 'C:\laragon\www\puntodeventa\public\uploads_users',
'server_webapp_path' => 'c:/www/www/puntodeventa_pwa/',
]
?>
En si el guarda un array en mi campo IMAGE que es tipo text en la BBDD, donde esta la ruta y demás cosas que mas adelante voy a utilizar.
Tengo otro proyecto donde funciona bien, no entiendo porque me da ese error y nunca me había dado ese error en el otro proyecto, gracias de ante mano ante cualquier sugerencia que puedan brindarme
FilesystemManager.php on line 183
es en donde uno comiensa a buscar en sentido contrario...