strpos(): Argument #1 ($haystack) must be of type string, array given

I'm newbie in Laravel, and follow a free course in Laracast. This is link of my course my_cource (episode 11 at 2:49s).

Summary of my problem: I'm trying to make my code more declarative with what I wan't to do (more specific is make a class name: Post, and a method: find() inside this class). This file declare Post class:

Model/Post.php:

<?php

namespace App\Models;

class Post
{
    public static function find($slug)
    {
        //don't write any thing in this function, 
        //i expected an blank page (not an error page like my bug)
    }
}

And this file direct url when user click:

routes/web.php:

<?php

use Illuminate\Support\Facades\Route;
use App\Models\Post;

Route::get('/', function () {
    return view('posts');
});

Route::get('posts/{post}', function ($slug) {
    //find post with slug and pass it intos posts view (through $post variable)
    $post = Post::find($slug);
    return view([
        'post' => $post
    ]);

})
    ->where('post', '[A-z_-]+');

This file return Html page, it's view of user (what user see in browser):

views/post.blade.php:

<body>
    <article>
        <?= $post ?>
    </article>
</body>
</html>

This is what I expect: Expect result

But this is the real I received: strpos(): Argument #1 ($haystack) must be of type string, array given

Error say: strpos(): Argument #1 ($haystack) must be of type string, array given

Thanks so much.


Solution 1:

In the return, method view should have a string, then maybe followed by the array data

Route::get('posts/{post}', function ($slug) {variable)
    $post = Post::find($slug);

    return view('post', [
        'post' => $post
    ]);

})
    ->where('post', '[A-z_-]+');