小编Fel*_*lan的帖子

Laravel 5:路径绑定返回空对象

我正在尝试使绑定​​工作(遵循youtube上的教程).在这一点上,我基本上是复制粘贴代码; 它仍然没有用.

这是routes.php:

Route::model('song', 'App\Song');

Route::get('songs', 'SongsController@index');
Route::get('songs/{slug}', 'SongsController@show');
Route::get('songs/{slug}/edit', 'SongsController@edit');
Route::patch('songs/{slug}', 'SongsController@update');
Run Code Online (Sandbox Code Playgroud)

Song.php:

<?php
namespace App;

use Illuminate\Database\Eloquent\Model as Eloquent;

class Song extends Eloquent {

    protected $fillable = [
        'title', 'lyrics'
    ];
}
Run Code Online (Sandbox Code Playgroud)

和SongsController.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Routing\Controller;
use Illuminate\Http\Request;

use App\Http\Requests;

use App\Song;

class SongsController extends Controller
{
    public function index(Song $song) {

        $songs = $song->get();

        return view('songs.index', compact('songs'));
    }

    public function show(Song $song) {

        return view('songs.show', compact('song'));
    }

    public function edit($slug) {

        $song = …
Run Code Online (Sandbox Code Playgroud)

binding routes model object laravel

-1
推荐指数
1
解决办法
2435
查看次数

标签 统计

binding ×1

laravel ×1

model ×1

object ×1

routes ×1