我可以使用以下命令创建模型和资源控制器(绑定到模型)
php artisan make:controller TodoController --resource --model=Todo
Run Code Online (Sandbox Code Playgroud)
我想用上面的命令创建一个迁移,有可能吗?
vue app在里面: C:\xampp\htdocs\booking
Laravel api在里面: C:\xampp\htdocs\booking-api
仅供参考:vue app正在开发http:// localhost:8080
如果文件夹结构如上所述,那么app工作正常我可以像这样调用api,
axios.get('http://localhost/booking-api/public/Rooms').then((response)=>this.items = response.data);
Run Code Online (Sandbox Code Playgroud)
但我想要booking-api文件夹内的booking文件夹.如果我放置它,如果我打电话给api如下,
axios.get('/booking-api/public/Rooms').then((response)=>this.items = response.data);
Run Code Online (Sandbox Code Playgroud)
它不会工作,控制台窗口是这样的,
Request URL:http://localhost:8080/booking-api/public/Rooms
Request Method:GET
Status Code:404 Not Found
Run Code Online (Sandbox Code Playgroud)
那么,我如何api在vueapp中放置项目以及如何从vue调用api.
我只需roomnumber要从以下查询返回的数组:
$roomnumbers = Room::with(['floorroomcount' => function($query){
$query->with('roomnumber')->get();
}])->where('roomtype_id', $roomtype_id)->get();
Run Code Online (Sandbox Code Playgroud)
尝试:以下采摘正在回归 floorroomcount
$roomnumbers->pluck('floorroomcount');
Run Code Online (Sandbox Code Playgroud)
但我需要roomnumber阵列,我怎么能得到?
对于酒店预订系统,我将获得总房间数和预留房间数.
可用房间数为:5
用户被预订该房间从:2018-02-22到:2018-02-24
但是如果用户搜索日期25和26,则下面的计数为零.一定有问题,我的'<='还是'>=',但我不能能找到.
$reservedCount = Reservation::where('check_in', '>=', $checkin_date)->where('check_out', '<=', $checkout_date)->count();
$reservedCount = Reservation::
whereBetween('check_in', [$checkin_date, $checkout_date])
->whereBetween('check_out', [$checkin_date, $checkout_date])
->count();
Run Code Online (Sandbox Code Playgroud)
以上两个查询也会在我做错的地方重新调整为零?
$checkin_date并且$checkout_date是用户输入的日期.
有一个酒店预订应用程序。
我想获得This Weeks预订计数Last Weeks预订计数。
所以我通过下面的查询实现了这一点,它按周数给出日期。我想排序。
查询:
$byweek = Reservation::all()->groupBy(function($date) {
return Carbon::parse($date->check_in)->format('W');
});
Run Code Online (Sandbox Code Playgroud)
输出是这样的:
这里16和17是周数,我该怎么样就得到17和16?
我已经拥有的:
在模型中有这个:
protected $dates = [ 'applied_date' ];
Run Code Online (Sandbox Code Playgroud)
在数据库中applied_date就是以这种格式存储的2018-05-11 13:31:59。
因此,我可以将其格式化如下:
$applied_date->format('m/d/Y')
Run Code Online (Sandbox Code Playgroud)
我想要的是:
在数据库applied_date中已经以这种格式存储1530205690(unix 时间戳)。
我想在视图中格式化,$applied_date->format('m/d/Y')我该如何实现?
注意:我们可以 Carbon::createFromTimestamp($applied_date)->format('m/d/Y');
laravel ×6
laravel-5.4 ×2
artisan ×1
laravel-5.6 ×1
mysql ×1
php ×1
vue-cli ×1
vue.js ×1
vuejs2 ×1