【问题标题】:how to get current view name (pagename) in laravel 5.7如何在 laravel 5.7 中获取当前视图名称(页面名称)
【发布时间】:2019-04-06 16:12:36
【问题描述】:

我有这样的路线http://localhost:8000/admin/edit-profile/13 我的页面名称是 edit-profile.blade.php 我只想从这条路线上得到edit-profile。 任何想法如何完成这项任务? 任何帮助将不胜感激...

【问题讨论】:

    标签: laravel url routes


    【解决方案1】:
    You can pass the reference like this one, but still you need the id in the url either before edit or after edit depends upon your route -
    
    public function editProfile(ModelClass $id){ //$id holds all the data as per the id
     $data = $id;
     return view('edit-profile',compact('data'));
    
    }
    

    【讨论】:

      【解决方案2】:

      您可以使用Request::segment() 获取url() 的任何片段,例如:

      {{ Request::segment(1) }}
      

      Reference

      【讨论】:

        【解决方案3】:

        你应该试试这个:

        控制器

        public function editProfile($id){
         $rsltTest = yourModelName::find($id);
         return view('edit-profile',compact('rsltTest'));
        
        }
        

        路线

        Route::get('edit-profile/{id}', 'ProfileController@editProfile')->name('edit-profile');
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-12-18
          • 2011-06-17
          • 2017-11-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-04-20
          • 2011-09-12
          相关资源
          最近更新 更多