duanguilin2007 2017-08-04 09:01
浏览 33
已采纳

为什么我不能从我的桌子上得到param?

I have tabel: tags(id,name,created_at, updated_ad)

I have model:

tag

class Tag extends Model
{
    protected $fillable = [
        'name',
    ];

    protected $dates = [
        'created_at',
        'updated_at',
    ];
    public function Posts()
    {
        return $this->morphedByMany(Post::class, 'taggable');
    }
}

I have tag controller:

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

I have routs:

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

I try to get tag with id, but it don't work. What i do wrong or what of forget define?

  • 写回答

1条回答 默认 最新

  • dongqun5769 2017-08-04 09:11
    关注

    The controller should like something like that:

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

    routes:

    Route::group(['namespace' => 'tags', 'prefix' => 'tags'], function () {
            Route::get('/{tag}', 'TagController@show');
            Route::delete('/{tag}', 'TagController@destroy')->middleware('auth:api');
        });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂