为什么我无法从桌上获得参数?

时间:2017-08-04 09:01:59

标签: php laravel laravel-5 php-7

我有表格:class Tag extends Model { protected $fillable = [ 'name', ]; protected $dates = [ 'created_at', 'updated_at', ]; public function Posts() { return $this->morphedByMany(Post::class, 'taggable'); } }

我有模特:

标签

class TagController extends Controller
{
    public function show(Tag $Tag)
    {
        return Response::json($Tag);
    }
}

我有标签控制器:

Route::group(['namespace' => 'Tags', 'prefix' => 'tags'], function () {
        Route::get('/{tags}', 'TagController@show');
        Route::delete('/{tags}', 'TagController@destroy')->middleware('auth:api');
    });

我有溃败:

path is not absolute: D:\xyz.csv

我尝试使用id获取标记,但它不起作用。我做错了什么或遗忘定义了什么?

1 个答案:

答案 0 :(得分:0)

控制器应该是这样的:

use App\Tag;

class TagController extends Controller
{
    public function show($tag)
    {
        return Response::json(Tag::find($tag));
    }
}

路线:

Route::group(['namespace' => 'tags', 'prefix' => 'tags'], function () {
        Route::get('/{tag}', 'TagController@show');
        Route::delete('/{tag}', 'TagController@destroy')->middleware('auth:api');
    });