我想在刀片中连接 javascript 变量{{ curly braces }},如下所示:
目前:
ajax: "{{ route(api.colors) }},"
我想要的是:
var page='colors';
...
ajax: "{{ route(api."+page+") }},"
Run Code Online (Sandbox Code Playgroud)
是否可以?
我可以运行php artisan migrate:refresh特定的表吗?还是可以总体上刷新特定的表迁移?
我尝试了这个:
php artisan migrate --path=/database/migrations/selected/
Run Code Online (Sandbox Code Playgroud)
但这不起作用!
我正在尝试访问laravel collection-> each之外的变量,但是我得到了..
Undefined variable: headers
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
public function bulkCoding(Request $request) {
Excel::load($request->file, function($reader) {
$headers = $reader->get()->first()->keys();
// Loop through all sheets
$reader->each(function($sheet) {
$headers->each(function ($title) {
dd($title);
});
});
});
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试重用查询变量,但看起来它采用最后分配的值而不是原始值,这就是我的意思:
$categories = DB::table('invoice_detail')
->selectRaw('SUM(qty) as qty')
->where('loc_id', '=', $user->loc_id)
->join('items', 'invoice_detail.item_id', 'items.barcode')
->where('items.active', '1')
->join('categories', 'items.category_id', 'categories.id')
->addSelect('categories.name')
->groupBy('categories.name');
dump($categories->get()); //It returns whole products, which is OK.
$topCategories = $categories->orderBy('qty', 'DESC')->take(5)->get();
dump($categories->get()); // It returns the top products, not the original value.
$downCategories = $categories->orderBy('qty', 'ASC')->take(5)->get();
Run Code Online (Sandbox Code Playgroud)
我想重用该$categories变量来获取Top Products并且Down Products没有查询重复。
但在第一次转储中,它返回整个产品,这是可以的,然后在获取 后Top Products,它返回顶级产品,而不是原始值。
有什么建议么?
我想循环
来自数据库的HTML字符串中的标签.
例:
$htmlString = "<p>1</p><p>2</p><p>3</p>";
Run Code Online (Sandbox Code Playgroud)
我想循环$htmlString变量并获得1,2,3,如下所示:
1
2
3
Run Code Online (Sandbox Code Playgroud)
我试过这个simplexml_load_string()功能:
$x = "<p>1</p><p>2</p>";
$xml = simplexml_load_string($x);
foreach ($xml->p as $p) {
{
echo $p;
}
}
Run Code Online (Sandbox Code Playgroud)
但它给出了错误:
Warning: simplexml_load_string(): Entity: line 1: parser error : Extra content at the end of the document
Warning: simplexml_load_string(): <p>1</p><p>2</p>
Warning: simplexml_load_string(): ^
Notice: Trying to get property 'p' of non-object
Warning: Invalid argument supplied for foreach()
Run Code Online (Sandbox Code Playgroud) laravel ×4
laravel-5.5 ×3
php ×3
blade ×1
collections ×1
each ×1
html ×1
javascript ×1
loops ×1
migrate ×1
migration ×1
mysql ×1
parsing ×1
reusability ×1
string ×1