小编QnA*_*ils的帖子

如果在路由组中定义了路由,则 Laravel 路由模型绑定不起作用

我有这条路线,

Route::get('/posts/show/{post}', 'PostsController@show');

//corresponding controller method
public function show(Post $post){
  //method logic
}
Run Code Online (Sandbox Code Playgroud)

当在 Route::group 之外定义路由时,这非常有效。

但这失败了;

Route::group(['domain' => '{user}.localhost.com'], function () {
...
    Route::get('/posts/show/{post}', 'PostsController@show');
...
}
Run Code Online (Sandbox Code Playgroud)

错误输出;

 Argument 1 passed to App\Http\Controllers\PostsController::show() must be an instance of App\Post, string given
Run Code Online (Sandbox Code Playgroud)

要查看作为参数传递的内容,我将 PostsController::show() 修改为以下内容;

public function show($post){
    return $post;
}

//it returned the subdomain part of the url.
Run Code Online (Sandbox Code Playgroud)

我可以肯定地说路线组正在按预期工作,因为我有其他路线并且它们有效。(只要他们不使用 Route-Model 绑定 ofc)

我发现其他 2 个帖子解决了同样的问题,但他们没有帮助我解决这个问题。

php laravel

2
推荐指数
1
解决办法
869
查看次数

Pusher 不在私人频道上广播 -PHP/Laravel

我已经为我的应用程序设置了 Pusher 和 Laravel Echo,以在某些事件触发时通知用户。

我已经测试过通过在“公共频道”上广播来查看设置是否有效,并成功地看到它有效。

这是事件本身:

class ItemUpdated implements ShouldBroadcast
{
  use Dispatchable, InteractsWithSockets, SerializesModels;

  public $item;

  public function __construct(Item $item)
  {
      $this->item = $item;
  }

  public function broadcastOn()
  {
      return new Channel('items');
  }
}
Run Code Online (Sandbox Code Playgroud)

公共频道:

Broadcast::channel('items', function ($user, $item) {
  return true;
});
Run Code Online (Sandbox Code Playgroud)

应用程序/资源/资产/js/bootstrap.js:

import  Echo from 'laravel-echo';
window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'my_key',
    cluster: 'eu',
    encrypted: true
});
Run Code Online (Sandbox Code Playgroud)

Laravel Echo 注册:(它位于我的主布局的“head”部分,事件触发视图从中延伸出来。)

<head>
<meta charset="utf-8">


<meta name="csrf-token" content="{{ csrf_token() }}">

<script src="{{ asset('js/app.js') …
Run Code Online (Sandbox Code Playgroud)

php laravel pusher

2
推荐指数
1
解决办法
6730
查看次数

标签 统计

laravel ×2

php ×2

pusher ×1