dongshi1868 2019-02-03 19:37
浏览 81

Laravel回显用于NON Auth :: User ID

Trying to work out if the following is possible:

I understand you can echo data in a blade via {{ Auth::user()->email }} to get email, {{ Auth::user()->name }} to get name, {{Auth::user()->id }} to get user ID etc.. and this is for the current logged in user.

But what i am trying to achieve is, if i type in a 'name' into a text field in a basic one field form, is there any way that i can have it dynamically show an echo of that 'name' related users ID, even though it is not that of the Auth::User ?

For Example: User ID: 1 with 'name' as ROGERHELLO can type in the 'name' POTATOHEAD and have it echo it's relative ID visible on the page which could be ID: 5?

I have searched about but cant seem to find a clear answer.. and hopefully this post can help others with a similar query in the future..

Thank you for any help!

  • 写回答

3条回答 默认 最新

  • doude1917 2019-02-03 20:28
    关注

    I understand you want to be able to search for users. If that is the case, try this:

    //in Controller
    public function search(Request $request)
    {
        $keyword = $request->get('search');
        $data = [];
    
        if (!empty($keyword)) {
            //you can search for anything here
            $data['users'] = User::where('name', 'LIKE', "%$keyword%")
                ->orWhere('email', 'LIKE', "%$keyword%")
                ->orWhere('occupation', 'LIKE', "%$keyword%")
                ->get();
        } else {
            //return a response to require an input 
        }
    
        return view('users.search', $data);
    }
    

    You can now display the search results on the view (users.search) returned.

    评论

报告相同问题?

悬赏问题

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