如何在控制器外部使用laravel雄辯模型?我似乎無法找出我應該使用的語句use "*insert class here*"
。我有一個助手類,經常會使用我的「類別模型」。如何在助手類中使用laravel雄辯模型
這是我使用的代碼。當我使用類別:
<?php
namespace Msh\Redirects;
use Illuminate\Support\Facades\Config as Config;
use Illuminate\Support\Facades\Input as Input;
/**
* This is the actual "product class" that generates the 301 redirect url's
*
* This is the product
*
* @author bgarrison
*/
class StorefrontRedirectsGenerator implements RedirectsGenerator {
public function generateUrls() {
// Set the database to the name of the domain
Config::set('database.connections.mysql_tenant.database', Input::get('domain'));
// Grab all the categories
$categories = Category::all();
// Use category information to determine request url's and target url's
$urlMapping = [];
$count = 0;
$categoryCount = 0;
foreach ($categories as $category) {
if ($category->Published == 1) {
$oldUrl = 'c-' . $category->CategoryID . '-' . $category->SEName . '.aspx';
$urlMapping['category_urls'][$oldUrl][] = $category->SEName . '.html';
$count++;
$categoryCount++;
}
if ($category->ParentCategoryID !== '0') {
$parentCategory = Category::where('CategoryID', '=', (int) $category->ParentCategoryID)->get();
foreach ($parentCategory as $pcategory) {
$url = $pcategory->SEName . '/' . $urlMapping['category_urls'][$oldUrl][0];
if (!in_array($url, $urlMapping['category_urls'][$oldUrl])) {
$urlMapping['category_urls'][$oldUrl][] = $url;
$count++;
$categoryCount++;
}
}
}
}
$urlMapping['category_urls']['count'] = $categoryCount;
return Response::json([
'success' => true,
'count' => $count,
'data' => $urlMapping
]);
}
}
這做到了!萬分感謝。我仍然習慣了這些年後的命名空間:) –
不客氣:) – lukasgeiter
我會將它標記爲答案asap –