Метод App \ Http \ Controllers \ Elibrary :: save не существует - PullRequest
0 голосов
/ 04 ноября 2019

Я пытаюсь сделать библиотеку PDF-файлов. который я хочу сохранить pdf title-name и имя файла также загрузить этот pdf в хранилище проекта. но сервер показывает мне эту ошибку. Я не могу понять, что я могу сделать.

Метод App \ Http \ Controllers \ Elibrary :: save не существует. мое сообщение об ошибке это мой файл elibrary контроллера, который я чек имя файла и сохранить имя файла в базе данных также хранится в public/images расположение

Я нахожу этот код по этой ссылке руководство по загрузке файла

       <?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Elibrary;
class ElibraryController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request){
        $elibrary = Elibrary::orderBy('id','DESC')->paginate(5);
        return view('e-library',compact('elibrary'))
            ->with('i', ($request->input('page', 1) - 1) * 5);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
     public function store(Request $request)
    {
        $this->validate($request, [
            'title' => 'required',
            'efile' => 'required|max:4000',
        ]);
        if($file= $request->file('file')){
            $name = $file->getClientOriginalName();
            if($file->move('images', $name)){
                $elibrary = new Post;
                $elibrary->efile = $name;
                $elibrary->save();
                return redirect()->route('e-library');
            };
        }
        $elibrary = new Elibrary([
            'title'    =>  $request->get('title'),
            'efile'    =>  $request->file('file'),
            ]);
        $elibrary->save();
        return redirect()->route('e-library');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

Это мой код файла маршрута

Route::post('/store', 'Elibrary@store')->name('store');

Это файл e-library.blade.php из

<form action="/store" method="post" enctype="multipart/form-data">
                @csrf()
                  <div class="form-group">
                     <input type="text" class="form-control"name="title" placeholder="Name">
                  </div>
                  <div class="form-group">
                     <input type="file" class="form-control"name="efile" >
                  </div>
                  <div class="form-group">
                     <input type="submit" class="btn btn-primary btn-send-message" >
                  </div>
               </form>

это мой файл модели Elibrary.php

    <?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Elibrary extends Model
{
    public $fillable = ['title','efile'];
}

это мой файл миграции

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateElibrariesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('elibraries', function (Blueprint $table) {
           $table->bigIncrements('id');
            $table->string('title');
            $table->string('efile');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('elibraries');
    }
}

Как я могу показать этот pdf с помощью функции show showв show.blade.php

Ответы [ 2 ]

2 голосов
/ 04 ноября 2019

Вы создаете новые экземпляры Elibrary в ваших методах контроллера. Elibrary - это класс контроллера, но похоже, что вы рассматриваете его как модель.

Возможно, попробуйте изменить все свои new Elibrary() на new Post, так как похоже, что это может быть то, что выпытаясь выполнить.

Если это так, вам также нужно сделать efile заполняемым в вашей Post модели.

0 голосов
/ 04 ноября 2019
$elibrary = Post::orderBy('id','DESC')->paginate(5);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...