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 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据