【发布时间】:2020-05-27 02:27:55
【问题描述】:
我正在尝试使用中间件过滤我的 http 请求。
我想检查我从 http 请求中获得的 "friends_id" 和我通过 Auth 传递的 "my_id" 是否已经不存在于同一行中, 如果他们这样做,我想重定向到主页,如果他们不这样做,我想执行正常请求,最终将插入我正在检查的数据
错误是“尝试获取非对象的属性'friends_id'”
这是我的“朋友”中间件:-
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
class Friends
{
public function handle($request, Closure $next)
{ $auth = Auth()->user()->id;
$dost = $request->friends_id;
$ip = DB::table('friends')
->where('my_id', '=', $auth)
->where('friends_id', '=', $dost)
->get();
if($ip->friends_id != $dost){
return $next($request);
}
return redirect('/home');
}
}
这是我的好友表:-
public function up()
{
Schema::create('friends', function (Blueprint $table) {
$table->id();
$table->string('my_id');
$table->string('friends_id');
$table->string('name');
$table->timestamps();
});
}
这是我的路线:-
Route::post('/f', 'FriendsController@store')->middleware('friends');
-谢谢你
【问题讨论】:
标签: database laravel laravel-middleware