如何在控制器外部使用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 –