0

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!

1
  • What version of Laravel are you using? There are more elegant and easier ways to do it. Can try and give you a working code once I know the Laravel version Commented Oct 30, 2017 at 11:10

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.