douque8855 2016-06-10 15:46
浏览 548
已采纳

Laravel ORM将结果作为对象数组

I have two simple problems in my laravel project

1.ORM getting result as objects

Here is my query to get details that matches an email

$users =User::where('user_email',$request->email)->first()->toArray();

Now i will get the result as array,but i need the result as objects.

eg: i need to read echo $users->user_email;

2.Named routes didn't worked

In my routes file i've this

Route::post('login',['as'=>'validatelogin','uses'=>'LoginController@login']);

And in my view

<form role="form" action="{{ url('validatelogin') }}" method="post">

But i will get methodnotfound exception

Laravel version:5.2

  • 写回答

1条回答 默认 最新

  • duanmuybrtg1231 2016-06-10 15:47
    关注
    1. Remove ->toArray() part from the query. This method converts collection or object to an array.

    2. Use {{ route('validatelogin') }} instead of url() helper. To check if route has name run php artisan route:list command.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?