1

I am making simple file upload page.
My html code -

<form action="{{ $work_id }}/upload/" method="get" enctype="multipart/form-data">
    @csrf
    <div class="row">
        <div class="col-10">
            <input type="file" class="custom-file-input" id="customFile" name="upload_file">
            <label class="custom-file-label" for="customFile">Faýly saýlaň</label>
        </div>
        <div class="col-2">
            <input class="btn btn-outline-primary" type="submit" name="upload_file_submit" id="upload_file_submit" value="Ýüklemek">
        </div>
    </div>
</form>

My code in controller -

function uploadWorkFile(Request $request, $login, $work_id){
    $teacher_id_result = DB::select('select `id` from teacher where login = ?', [$login]);
    $teacher_id = $teacher_id_result[0]->id;
    $path = $request->file('upload_file')->storeAs('teacher_works/'.$teacher_id.'/'.$work_id.'/', $request->input('upload_file'));
    return $path;
}

My code in web.php

Route::get('/teacher/{login}/work_list/{work_id}/upload', 'TeacherController@uploadWorkFile');

I don't understand what happens there, please help, thanks.

8
  • 1
    Does this answer your question? Problems with file upload in Laravel Commented Jan 7, 2021 at 17:30
  • Did you add encrypted attribute inside your form tag, example in<form action="/your_route" method="post" enctype="multipart/form-data"> Commented Jan 7, 2021 at 17:30
  • Yes I tried, same error - Call to a member function storeAs() on null Commented Jan 7, 2021 at 17:34
  • dd($request->all()) add this to your function to debug...maybe it's not getting the file Commented Jan 7, 2021 at 17:58
  • what I get - array:3 [▼ "_token" => "hLUJbuE4Mi8Wnk8ouIXfGxbGRDkXgt4dPZy6IBx9" "upload_file" => "screen.png" "upload_file_submit" => "Ýüklemek" ] Commented Jan 7, 2021 at 18:03

0

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.