嗨,我真的是新手在Laravel。所以我真的需要一些帮助,我需要从$ report-> reportable_type中获取最后一个单词,并从reportable_type获取App/Models/Store和App/Models/Product。所以我想爆炸斜线(/)并得到最后一个词它意味着商店或产品。php - 如何使用laravel从斜线(/)爆炸并得到硬汉
我的控制器中的代码其工作,但它使用print_r,我不想使用print_r。
这是我的控制器
public function toLink($id)
{
$report = $this->reportRepository->findWithoutFail($id);
//get Store Name
$name = Store::where('id','=',$report->reportable_id)->pluck('name')->all();
$storename = $name[0];
//get Store ID
$idstore = Store::where('id','=',$report->reportable_id)->pluck('id')->all();
$storeid = $idstore[0];
if(empty($report))
{
Flash::error('Report not found');
return redirect(route('reports.index'));
}
$report_type = $report->reportable_type;
print_r (explode("/",strrpos($report_type, '/') + 1),$report_type);
return redirect(env('FRONTEND_URL') ."/".str_slug($reportable_type)."/$storeid/".str_slug($storename));
}
[请不要发布您的代码为图像。(// meta.stackoverflow.com/q/285551) –
友情提醒:避免张贴代码图像](https://开头元。 stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question/285554#285554)。相反,将代码文本复制并粘贴到问题主体中。 –