gpt4 book ai didi

php - 从 Laravel 中的 mysql 表中检索值

转载 作者:行者123 更新时间:2023-11-29 19:36:23 26 4
gpt4 key购买 nike

我的MessageController如下:

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use App\Http\Requests;
use App\Message;


class MessageController extends Controller
{
public function CreateMessage(Request $request)
{

$meso = new Message();
$meso->body = $request['body'];
$meso->subject = $request['subject'];


$request->user()->messages()->save($meso) ;


return redirect()->route('mail');
}
public function getmailbox()
{
$message = Message::orderBy('created_at', 'desc')->get();
return view('dashboard', ['messages' => $message]);
}
}

我正在尝试在我的 mail.blade.php 中检索消息:

<table class="table table-inbox table-hover">
<tbody>
@foreach($messages as $message)
<tr class="unread">
<td class="inbox-small-cells">
<input type="checkbox" class="mail-checkbox">
</td>
<td class="inbox-small-cells"><i class="fa fa-star"></i></td>
<td class="view-message dont-show">Facebook</td>
<td class="view-message view-message"><p>{{ $message->body }}</p></td>
<td class="view-message inbox-small-cells"><i class="fa fa-paperclip"></i></td>
<td class="view-message text-right">feb 14</td>
</tr>
</tbody>
@endforeach
</table>

但是这是我从该查询中得到的结果:ed6d9659a06e690c67323133798cd26570bdc7a9.php 第 200 行中出现 ErrorException: undefined variable :消息(查看:C:\xampp\htdocs\dating\resources\views\mail.blade.php)这里有任何帮助

最佳答案

Laravel 5

更改函数结构:

public function CreateMessage(Request $request)
{

$meso = new Message();
$meso->body = $request['body'];
$meso->subject = $request['subject'];

$meso->save();
//$request->user()->messages()->save($meso) ;

/**
* You can get the last inserted ID
*
* If your message table having primaty key column name is id
*/

// $last_insert_id = $meso->id;


return redirect()->route('mail');
}
public function getmailbox()
{
$message = Message::orderBy('created_at', 'desc')->get();
return view('mail', ['messages' => $message]);
}

关于php - 从 Laravel 中的 mysql 表中检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41543816/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com