方法App \ Http \ Controllers \ Elibrary :: save不存在

我尝试制作pdf文件库。我要存储pdf标题名称和文件名的文件,也将该pdf上载到项目存储中。但是服务器向我显示此错误。我不知道该怎么办。

  

方法App \ Http \ Controllers \ Elibrary :: save不存在。   my error message   这是我的elibrary控制器文件,我将检查文件名并将文件名存储在数据库中,该文件名也存储在public/images

我在此链接上找到此代码uload file tutorial

       <?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');
    }
}
  

我如何在show.blade.php

中使用帮助显示功能显示此pdf文件
hechacn 回答:方法App \ Http \ Controllers \ Elibrary :: save不存在

您正在控制器方法中创建Elibrary的新实例。 Elibrary是一个控制器类,但您似乎将其视为模型。

也许您尝试将所有new Elibrary()更改为new Post,因为这似乎是您要实现的目标。

在这种情况下,您还需要在efile模型中填充Post

,
$elibrary = Post::orderBy('id','DESC')->paginate(5);
本文链接:https://www.f2er.com/3165394.html

大家都在问