Nikita Abramov
Nikita Abramov

Reputation: 162

Error in file (Laravel)

Hello I've downloaded package in laravel - "Flysystem". So to say I Decide to add article , but I got error.

First action: save file in: "public/storage/rubrick ."

Second action: entry in database, exception in the field "images" value X:\userdata\temp\phpF2CC.tmp - i dont know. it Right ?

In general, I get error:

enter image description here

My file code "filesystem.php" -

'default' => env('FILESYSTEM_DRIVER', 'local'),

'cloud' => env('FILESYSTEM_CLOUD', 's3'),

 'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app/public/storage/rubrick'),
    ],

    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/img/storage',
        'visibility' => 'public',
    ],

Code in order to send add my article :

public function sendArticle(AddArticle $request){
    $data=$request->all();

    if(AddArticles::create([
        'name' => $data['add'],
        'message' => $data['description'],
        'author' => Auth::user()->login,
        'images'=>$data['file'],
    ])){
        Storage::disk('local')->put($data["file"], 'load');
       return redirect()->route("aboutus")->with("successArticle","Статья была успешна добавлена");

    }

}

And dump(file):

enter image description here

In advance Thanks for the help!

Upvotes: 0

Views: 51

Answers (1)

Dharma Saputra
Dharma Saputra

Reputation: 1674

You are passing UploadedFile object to image attribute of AddArticle. It should string not object. You should store it first and then assign it to variable. Example:

$image = $request->file('image')->store('image');
Article::create([
    ...
    "image" => $image,
    ...
])

Hope it helps

https://laravel.com/docs/5.5/filesystem#storing-files - File Uploads section

Upvotes: 1

Related Questions