我已经完成了我正在处理的大部分应用程序,现在我觉得我陷入了一个变化.我有这样做的想法,但问题我真的无法实现它.我希望我能在这里找到一些帮助.
我有这个复杂的代码.它需要两个日期并检查car_reservation数据透视表是否重叠.
$table->integer('car_id')->unsigned();
$table->foreign('car_id')->references('id')->on('cars');
$table->integer('reservation_id')->unsigned();
$table->foreign('reservation_id')->references('id') >on('reservations');
Run Code Online (Sandbox Code Playgroud)
关系在预订模型中:
public function cars()
{
return $this->belongsTo('App\Models\Access\Car','car_reservation');
}
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试调试并使其工作的代码:
public function get(Request $request)
{
$appointments = Reservation::with('cars')->get();
foreach ($appointments as $appointment) {
$from = Carbon::parse($request->from);
$to = Carbon::parse($request->to);
$eventStart = Carbon::instance(new DateTime($appointment['dt_start']));
$eventEnd = Carbon::instance(new DateTime($appointment['dt_end']))->subSecond(1);
// A spot is taken if either the from or to date is between eventStart and eventEnd
// or if the evenStart and eventEnd are between the from and to date.
if ($from->between($eventStart, $eventEnd) ||
$to->between($eventStart, $eventEnd) …Run Code Online (Sandbox Code Playgroud) 我设置了一个事件和新频道:
class TaskCreated implements shouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $task;
public function __construct(Task $task)
{
$this->task = $task;
}
}
Run Code Online (Sandbox Code Playgroud)
并安装 Echo 并进行设置
import Echo from "laravel-echo"
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'pusher-key',
cluster: 'ap2',
encrypted: true
});
Run Code Online (Sandbox Code Playgroud)
然后我在发布任务时调用 TaskCreated 事件
event(new TaskCreated($task));
Run Code Online (Sandbox Code Playgroud)
然而,问题是 Echo 不听推送日志或任何东西。即使在 laravel-websockets 中,事件是作为 api 消息创建的。
这是 vue js Echo 实现:
mounted () {
axios.get('/tasks').then(response => (this.tasks = response.data));
Echo.channel('taskCreated').listen('TaskCreated', (e) => {
console.log(e);
this.tasks.push(task.body)
});
Run Code Online (Sandbox Code Playgroud)
在仪表板中:
api-message Channel: …
首先)添加搜索栏以查看:
{!! Form::open(['method'=>'GET','url'=>'home','class'=>'navbar-form navbar-left','role'=>'search']) !!}
<div class="input-group custom-search-form">
<input type="text" class="form-control" name="search" placeholder="Search...">
<span class="input-group-btn">
<button class="btn btn-default-sm" type="submit">
<i class="fa fa-search">i
</button>
</span>
Run Code Online (Sandbox Code Playgroud)
第二)我的控制器我将所有用户显示在一个表格中,搜索栏位于其上
public function index()
{
$user = User::all();
$search = \Request::get('search'); the param of URI
$users = User::where('name','=','%'.$search.'%')
->orderBy('name')
->paginate(20);
return view('home',compact('users'))->withuser($user);
}
Run Code Online (Sandbox Code Playgroud)
这是表格的样子
@foreach($user as $users)
<th scope="row">1</th>
<td><a href="{{ url('/user').'/'.$users->id }}">show</a></td>
<td>{{$users->name}}</td>
<td>{{$users->city}}</td>
<td>{{$users->phone}}</td>
<td>{{$users->street}}</td>
<td>{{$users->national_id}}</td>
<td>{{$users->name}}</td>
</tr>
@endforeach
Run Code Online (Sandbox Code Playgroud)
我想要的是当我在栏中搜索时我想做一个像这样的循环@foreach($ users as $ user){{$ user-> name}} @endforeach并将视图替换为搜索到的名称只要.这是索引的路线
Route::get('/home', 'HomeController@index');
Run Code Online (Sandbox Code Playgroud)
我该怎么办?对不起提前提出长问题.
我正试图每秒重新加载我的tableview.我现在重新加载tableview对象,但由于我Order在重新加载之前清除数组,因为索引超出范围而崩溃.
这是我目前的代码
var orders = [Order]()
override func viewDidLoad() {
super.viewDidLoad()
// table stuff
tableview.dataSource = self
tableview.delegate = self
// update orders
var timer = Timer.scheduledTimer(timeInterval: 4, target: self, selector: "GetOrders", userInfo: nil, repeats: true)
GetOrders()
}
func numberOfSections(in tableView: UITableView) -> Int {
if orders.count > 0 {
self.tableview.backgroundView = nil
self.tableview.separatorStyle = .singleLine
return 1
}
let rect = CGRect(x: 0,
y: 0,
width: self.tableview.bounds.size.width,
height: self.tableview.bounds.size.height)
let noDataLabel: UILabel = UILabel(frame: rect)
noDataLabel.text = …Run Code Online (Sandbox Code Playgroud) 我的OneSignal模块有问题。它没有给我提供这样的模块OneSignal,而是由可可豆荚安装了它并use_frameworks!放在我的豆荚文件中。我真的不知道我还需要配置什么才能使其正常工作
我在这里尝试了其他解决方案,例如:
荚文件
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
target 'Jaee2' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Jaee2
pod 'OneSignal', '>= 2.5.2', '< 3.0'
end
target 'OneSignalNotificationServiceExtension' do
use_frameworks!
pod 'OneSignal', '>= 2.5.2', '< 3.0'
end
Run Code Online (Sandbox Code Playgroud) 当我删除respond_toand 时render to view,一切正常,但添加js render会出现错误。
控制器代码:
if params[:stock].present?
@data = params[:stock]
@stock = Stock.new_form_lookup(params[:stock])
respond_to do | format |
format.js {render partial: 'user/result'}
end
else
flash[:danger] = "no search found "
redirect_to my_portfolio_path
end
Run Code Online (Sandbox Code Playgroud)
结尾
查看代码:
<%= form_tag searchstock_path , remote: true , method: :get, id:"stock-search" do %>
Run Code Online (Sandbox Code Playgroud)
application.js 代码:
//= rails-ujs
//= require jquery
//= require bootstrap
//= require jquery_ujs
//= require turbolinks
//= require_tree .
Run Code Online (Sandbox Code Playgroud) 错误 ITMS-90206:“无效的捆绑包。‘app.app/PlugIns/OneSignalNotificationServiceExtension.appex’中的捆绑包包含不允许的文件‘Frameworks’。” 错误 ITMS-90206:“无效的捆绑包。‘app/PlugIns/OneSignalNotificationServiceExtension.appex’中的捆绑包包含不允许的文件‘Frameworks’。”
在我的应用项目中
Always Embed Swift Standard Library = No
Embedded Content Contains Swift = Yes
在我的目标
Always Embed Swift Standard Library = Yes
Embedded Content Contains Swift = Yes
在 OneSignalNotificationServiceExtension 中
Always Embed Swift Standard Library = No
Embedded Content Contains Swift = NO
当我尝试将 OneSignalNotificationServiceExtension 更改为 YES 时,它显示的错误import OneSignal不是No such module 'OneSignal
OneSignal 是用 Swift 编写的,应该与 use_frameworks 一起导入!
internal func rangeFromNSRange(_ nsRange: NSRange) -> Range<String.Index>? {
let from16 = utf16.startIndex.advanced(by: nsRange.location)
let to16 = from16.advanced(by: nsRange.length) //advanced(by:) is unavailable
if let from = String.Index(from16, within: self),
let to = String.Index(to16, within: self) {
return from ..< to
}
return nil
}
Run Code Online (Sandbox Code Playgroud)
我在swift 3中有这个文件,我正在尝试将其转换为swift 4但是我得到了这个错误,也是这个错误
public func height(_ width: CGFloat, font: UIFont, lineBreakMode: NSLineBreakMode?) -> CGFloat {
var attrib: [String: AnyObject] = [NSAttributedStringKey.font.rawValue: font]
if lineBreakMode != nil {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = lineBreakMode!
attrib.updateValue(paragraphStyle, forKey: NSAttributedStringKey.paragraphStyle.rawValue) …Run Code Online (Sandbox Code Playgroud) 我有一个受保护的 api,我得到了它的用户名和密码。当我使用 Postman 时,我选择了“Basic Auth”类型,在正文中我有用户登录信息等参数。它工作得很好。
但是,我正在尝试使用 Alamofire 做同样的事情,但我无法获得正确的 JSON 返回值。这是我所做的:
// user auth
let param = ["mobile":"3", "password":"100200"]
let urlStr = "http://MyApi.com/api/login"
let url = URL(string: urlStr)
// api auth
let user = "apiUserName"
let password = "ApiAuthPassword"
var headers: HTTPHeaders = ["mobile":"001",
"password":"1111"]
if let authorizationHeader = Request.authorizationHeader(user: user, password: password) {
headers[authorizationHeader.key] = authorizationHeader.value
}
Alamofire.request(url!, headers: headers)
.responseJSON { response in
print(response.result.value)
if let value: AnyObject = response.result.value as AnyObject? {
//Handle the results as JSON
print(value) …Run Code Online (Sandbox Code Playgroud)