小编leo*_*019的帖子

编写预订代码(API)

我已经完成了我正在处理的大部分应用程序,现在我觉得我陷入了一个变化.我有这样做的想法,但问题我真的无法实现它.我希望我能在这里找到一些帮助.

我有这个复杂的代码.它需要两个日期并检查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)

php mysql laravel laravel-5.3

8
推荐指数
1
解决办法
415
查看次数

Laravel Echo 不听

我设置了一个事件和新频道:

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: …

php laravel vue.js laravel-websockets laravel-7

7
推荐指数
2
解决办法
7790
查看次数

Laravel 5.3中的搜索栏过滤表格

首先)添加搜索栏以查看:

{!! 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)

我该怎么办?对不起提前提出长问题.

html php search laravel blade

5
推荐指数
1
解决办法
1万
查看次数

RealTime Reload UITableview没有"Index out of Range"swift

我正试图每秒重新加载我的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)

real-time uitableview ios swift swift3

5
推荐指数
3
解决办法
2687
查看次数

没有这样的模块OneSignal

我的OneSignal模块有问题。它没有给我提供这样的模块OneSignal,而是由可可豆荚安装了它并use_frameworks!放在我的豆荚文件中。我真的不知道我还需要配置什么才能使其正常工作

我在这里尝试了其他解决方案,例如:

得到错误没有使用Xcode的此类模块,但是框架在那里

在此处输入图片说明

在此处输入图片说明

荚文件

# 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)

xcode notifications swift onesignal

5
推荐指数
1
解决办法
1078
查看次数

ActionController::UnknownFormat 添加 response_to 时

当我删除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)

javascript ajax ruby-on-rails-5.2

5
推荐指数
1
解决办法
303
查看次数

错误 ITMS-90205:“无效的捆绑包。‘NotificationServiceExtension.appex’中的捆绑包包含不允许的嵌套捆绑包。”

错误 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 一起导入!

xcode application-loader swift onesignal app-store-connect

4
推荐指数
1
解决办法
2513
查看次数

'advanced(by :)'不可用从swift 3转换为swift 4

 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)

xcode swift3 swift4

1
推荐指数
1
解决办法
761
查看次数

Alamofire 中的基本身份验证标头

我有一个受保护的 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)

authentication json swift alamofire

0
推荐指数
1
解决办法
6514
查看次数