最近我做了这个教程。
在这个应用程序中,我可以成功运行 vuejs 应用程序和axios.then.catch.finally或this.form.then.catch.finally.
但是我在我最近升级到 Laravel 5.7 的旧项目中添加了 npm。在我的应用程序中,我无法添加finally功能。如果我这样做,它说:
未捕获的类型错误:axios.post(...).then(...).catch(...).finally 不是函数
我的 app.js:
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
// require('./bootstrap');
import Vue from 'vue'
window.Vue = Vue
window.axios = require('axios');
import { Form, HasError, AlertError } from 'vform'
window.Form = …Run Code Online (Sandbox Code Playgroud) 我第一次使用 Passport laravel,但我仍然不太明白 midlewareare auth:api 和 client:credentials (CheckClientCredentials) 之间的区别,这两种类型的中间件不限制路由吗?它们之间有什么区别?
我正在尝试在其上构建应用程序Laravel,我想知道我们是否可以with在将模型注入控制器函数时使用关系,例如:
我有一个名为的模型Stream,我有一个名为Standard. Standard属于Stream所以我的代码看起来像:
class Standard extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $guarded = [];
public function stream()
{
return $this->belongsTo('Models\Stream', 'stream_id', 'id');
}
}
Run Code Online (Sandbox Code Playgroud)
现在在我的StandardController以下功能中显示模型:
public function show(Standard $standard)
{
return response()->json(['data' => $standard], 200);
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用,return response()->json(['data' => $standard->with('stream')], 200);但它没有相应地工作。有人可以建议我如何在这种情况下执行。
谢谢。
我正在将 Laravel 5.7 用于某些 api。我还使用包https://github.com/tymondesigns/jwt-auth生成 JWT 令牌来验证用户。我很久以前就配置了所有东西,它运行良好。
我在RouteServiceProvider.php以下注册路由组routes/api_v1.php:
Route::prefix('api/v1')
->middleware('api')
->namespace($this->namespace.'\API\V1')
->group(base_path('routes/api_v1.php'));
Run Code Online (Sandbox Code Playgroud)
在config.auth.php我有带有驱动程序 jwt 的 api_v1 防护:
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api_v1' => [
'driver' => 'jwt',
'provider' => 'users',
],
],
Run Code Online (Sandbox Code Playgroud)
我已经App/User.php实现Tymon\JWTAuth\Contracts\JWTSubject并实现了这两种方法。
但是当app/Http/Kernel.php我在中间件数组中添加时:
protected $routeMiddleware = [
// previous middlewares,
'jwt.auth' => \App\Http\Middleware\JWTAuthenticate::class
];
Run Code Online (Sandbox Code Playgroud)
routes/api_v1.php组下的路线jwt.auth:
路由::中间件(['jwt.auth'])->组(函数(){
// Keep auto resource route at bottom …Run Code Online (Sandbox Code Playgroud) 如何assertJsonCount使用带索引的嵌套数组进行调用?
在我的测试中,返回以下 JSON:
[[{"sku":"P09250"},{"sku":"P03293"}]]
Run Code Online (Sandbox Code Playgroud)
但是尝试使用会assertJsonCount返回以下错误:
$response->assertJsonCount(2);
// Failed asserting that actual size 1 matches expected size 2.
Run Code Online (Sandbox Code Playgroud) 我在用于身份验证的 Laravel 'users' 表中将列名从 'updated_at' 更改为 'last_updated_at'。
现在我在注册过程中收到此错误:
SQLSTATE[HY000]:一般错误:1 表帐户没有名为 updated_at 的列(SQL:插入“帐户”(“用户名”、“电子邮件地址”、“密码”、“updated_at”、“created_at”)值(... ))
如何让它使用新的列名?
laravel laravel-5 laravel-authorization laravel-authentication
我有这种情况,我想将数据传递给 Bootstrap 4 模式。我有一个记录列表,其中包含要编辑和删除的链接。由于我想加载一个模态确认来删除特定记录,所以我需要传递几个参数,例如destroy路由的ID。
我已经尝试过这个Laracasts 论坛的解决方案。但是,首先,脚本不起作用,因为 console.log 没有输出任何内容。
注意:我正在使用app.js,所以可能与问题有关,但我没有找到解决此问题的提示。
这是我的accounts.blade.php:
@extends('layouts.app')
@section('title','Accounts list')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col">
<div class="card">
<div class="card-header">
My accounts
</div>
<div class="card-body">
<h5 class="card-title">Accounts list</h5>
<h4><a href="{{ route('accounts.create') }}" class="btn btn-success">Create a new account</a></h4>
<hr>
<ul>
@forelse ($user->accounts as $account)
<li>
<a href="{{ route('accounts.show',$account->id) }}" title="Your accounts blah">{{ $account->name }}</a> || <a href="{{ route('accounts.edit', $account->id) }}">Edit</a> |
<button type="button" class="btn btn-outline-danger delete-company"
data-toggle="modal"
data-target="#exampleModal"
data-id="{{$account->id}}" …Run Code Online (Sandbox Code Playgroud) 我想查询用户并按年龄范围对他们进行分组
这是我到目前为止所做的
User::applicant()->get()
->groupBy(function ($item) {
return Carbon::parse($item->dob)->age;
})
->map(function ($collection) {
return $collection->count();
});
Run Code Online (Sandbox Code Playgroud)
这是我从上面的查询中得到的
现在想按年龄范围获取集合和订单
18-24: 1,
25-35: 5,
36-45: 89,
46+ : 84
Run Code Online (Sandbox Code Playgroud) 我想在 larave.log 文件中添加我的应用程序中的所有活动。我能够在其中添加用户登录名,但不能添加注销。
我使用 Laravel 5.8 和 mysql 5 数据库来做到这一点。
这是 HomeController 中用于注册登录用户加载主视图的代码。
public function index()
{
Log::info('Utente collegato: '.Auth::user()->name);
return view( config('configpath.user_home') );// loading user homepage
}
Run Code Online (Sandbox Code Playgroud)
下面的代码在 Laravel 默认的 LoginController 中
public function userLogout()
{
Log::info('User '.Auth::user()->name. 'has logged out');
Auth::guard('web')->logout();
return redirect()->route('login');
}
Run Code Online (Sandbox Code Playgroud)
使用注销时,我希望在登录时看到有关用户注销的消息,但我没有看到。有人可以给我一个解释吗?谢谢!
我有一个新的 Laravel 5.8 应用程序。我开始使用 Eloquent ORM 及其关系。
我马上就遇到了一个问题。
我有以下表格。(这只是一个示例,出于测试原因,不会成为实际应用程序)
Login table:
--------------------------
| id | user | data_id |
--------------------------
| 1 | admin | 1 |
| 2 | admin | 2 |
| 3 | admin | 3 |
--------------------------
Data table:
--------------
| id | ip_id |
--------------
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
--------------
IP table:
----------------------
| id | ip |
----------------------
| 1 | 192.168.1.1 …Run Code Online (Sandbox Code Playgroud) laravel-5 ×10
laravel ×7
eloquent ×2
php ×2
assert ×1
axios ×1
javascript ×1
json ×1
jwt-auth ×1
laravel-5.7 ×1
laravel-5.8 ×1
phpunit ×1
testing ×1
vue.js ×1