简体   繁体   中英

Laravel 5.3 on shared hosting; Page::findBySlug() returns null

I just pushed a Laravel website onto a shared hosting. Copied the public folder to the /www, changed the index.php to reflect the path change and configured my .htaccess, etc.

At first I was simply getting an error, telling me that Page::findBySlug() returned null. Checked again with dd(), was and still is null.

FrontendController@index is looking like this

public function index($slug)
{
    $page = Page::findBySlug($slug);
    $pageTemplate = $page->templates->first();
    return view('frontend.pages.index', compact('page','pageTemplate'));
}

and after toying with dd() for a while, it now sends me to the custom 500 unless it's supposed to pull the slug from db, in which case I get a custom 404.

EDIT: I pulled the same version of the app but with it being already installed (instead of rolling with composer instal) from the testing platform and it simply works so I doubt it has anything to do with the hosting. I'd still appreciate an answer given that I'd like to do it the correct way. Is there anything I should setup slugs-wise after running a fresh install?

What am I missing here? Thanks.

尝试$page= Page::where('slug',$slug)->first();

尝试将您的php版本更新为7.0。

Fixed by php artisan route:clear. Apparently route:cache wasn't the way to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM