Laravel 5是由Taylor Otwell创建的开源PHP Web开发MVC框架的当前主要版本。 Laravel使用简单,富有表现力的语法帮助您创建应用程序。使用laravel标签来解决一般的Laravel相关问题。
我想在 Laravel 中仅显示一年中的所有团队一次。我无法让 unique() 工作,因为我没有使用 select()。如何跳过 where() 中的重复值或如何包含
我想创建一个自定义中间件,只有当用户经过身份验证并且电子邮件是某个电子邮件才能访问 /admin 页面。 虽然,当我指定自定义路线然后重定向时......
我们必须在 Laravel 中的哪里编写查询:模型、控制器还是路由?
我对 Laravel 中的数据库查询有点困惑,我们必须在哪里编写查询:在控制器、模型或路由中? 我已经看过很多教程,我看到了很大的差异。
我有一个控制器,在名为“UserController”的控制器中具有“getUsers”功能,在其中我想调用“CarController”控制器的一个名为“getCars”的功能,这两个选项...
我已经构建了一个查询,我试图了解如何在一个查询中实现相同的目标。我对 Laravel 和学习还相当陌生。无论如何,有人可以帮助我......
我有一个用户 ID 数组,我正在尝试获取它们的集合。我一直在使用以下 foreach 循环,但我意识到对于它所做的每个循环,它都会覆盖以前的数据。 $用户...
find()、findOrFail()、first()、firstOrFail()、get()、list()、toArray()有什么区别
这些方法有什么区别: 寻找() 查找或失败() 第一的() 首先或失败() 得到() 列表() toArray() 我一直在使用它们,每一个都会给出不同的结果,有时我需要添加
Laravel JsonResource:array_merge_recursive():参数 #2 不是数组
我有一个 Post 的 JsonResource,它应该返回单个帖子。但在加入其他一些数据后,我收到此错误: array_merge_recursive(): Argument #2 is not an array。 这不起作用: /** *
我正在尝试实现智能搜索引擎这是教程链接 https://github.com/msurguy/laravel-smart-search。 我知道 Laravel 4 的这个教程,我正在尝试在 Laravel 5 中实现....
我正在尝试实现智能搜索引擎这是教程链接 https://github.com/msurguy/laravel-smart-search 我知道 Laravel 4 的这个教程,我想在 Laravel 5.2 中实现 ...
[Vue warn]:安装钩子时出错:“ReferenceError:google未定义”
我正在尝试使用此链接实现 Google 自动完成功能: https://www.npmjs.com/package/vue-google-autocomplete 但我收到这个错误: VM2823 app.js:62045 [Vue warn]: 安装的钩子出错:...
我在 Laravel 平台中有一个脚本,它处理数千条记录,并且出现超时问题。我想避免更新服务器上的设置,例如 php.ini 文件。 有什么办法可以将所有记录分块...
我实现了一个徽标上传系统。马上就会生效。需要刷新页面才能看到效果。我想知道如何阻止它。 免疫组化 我实现了一个徽标上传系统。它会立即生效。需要刷新页面才能看到效果。我想知道如何阻止它。 IMG <img id="userLogo" src="/images/account/operator/logo.png" alt="" class="thumbnail img-responsive"> 表格 {!! Form::open(array('url' => '/profile/logo/update', 'class' => 'form-horizontal', 'role' =>'form','id' => 'editLogo','files'=>true)) !!} <input name="logo_path" type="file"> <br><br> <button class="btn btn-success btn-sm mr5" type="file"><i class="fa fa-user"></i> Update Logo</button> {{ csrf_field() }} {!! Form::close();!!} 控制器 public function updateLogo(){ $inputs = Input::all(); $logo_path = array('logo_path' => Input::file('logo_path')); $rule = ['logo_path' => 'max:100|mimes:jpeg,bmp,png']; $id = Auth::user()->account_id; $type = Auth::user()->account_type; $validator = Validator::make($logo_path, $rule ); if ( $validator->fails()) { return Redirect::to('/profile/')->withErrors($validator)->withInput(); } else { $old_logo_path = public_path().'/images/account/operator/logo.png'; $delete = File::delete($old_logo_path); if (Input::hasFile('logo_path')) { $file = Input::file('logo_path'); $destinationPath = public_path().'/images/account/operator/'; $uploadSuccess = $file->move($destinationPath, 'logo.png'); } return Redirect::to('/profile/') ->with('success','Your company logo was updated succesfully!'); } } 结果 我的文件已保存到我想要的位置。但是,当旧徽标仍然显示在页面上时,除非我刷新页面,否则我会看到新徽标。 这是因为图像已缓存在浏览器中,并且由于您正在更新同名的图像,浏览器会显示已缓存的图像。因此,更好、更有效的解决方案是每次上传图像时都有一个唯一的文件名,或者每次提供图像时都可以将查询字符串附加到图像路径。 <img id="userLogo" src="/images/account/operator/logo.png?q=<?php echo microtime(); ?>" alt="" class="thumbnail img-responsive">
我在 Laravel 中使用 JWT 进行用户身份验证 验证控制器: 我在 Laravel 中使用 JWT 进行用户身份验证 身份验证控制器: <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use App\Models\User; use Illuminate\Auth\Events\Verified; use Validator; use Illuminate\Support\Str; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Notification; class AuthController extends Controller { public function __construct() { $this->middleware('auth:api', ['except' => ['login', 'register']]); } /** * Get a JWT via given credentials. * * @return \Illuminate\Http\JsonResponse */ public function login(Request $request){ $validator = Validator::make($request->all(), [ 'email' => 'required|email', 'password' => 'required|string|min:6', ]); if ($validator->fails()) { return response()->json($validator->errors(), 422); } if (! $token = auth()->attempt($validator->validated())) { return response()->json(['status'=>true,'error_message' => 'Invalid Credentials'], 401); } return $this->createNewToken($token); } /** * Register a User. * * @return \Illuminate\Http\JsonResponse */ public function register(Request $request) { $messages = [ 'password.confirmed' => 'Password Confirmation should match the Password', 'password.min' => ' Password should be minimum 6 digits', ]; $validator = Validator::make($request->all(), [ 'name' => 'required|string|between:2,100', 'email' => 'required|string|email|max:100|unique:users', 'password' => 'required|string|confirmed|min:6', ],$messages); if($validator->fails()){ return response()->json($validator->errors(), 422); } $user = User::create(array_merge( $validator->validated(), ['password' => bcrypt($request->password)] )); return response()->json([ 'message' => 'Successfully registered', ], 201); } /** * Log the user out (Invalidate the token). * * @return \Illuminate\Http\JsonResponse */ public function logout() { auth()->logout(); return response()->json(['message' => 'User successfully signed out']); } /** * Refresh a token. * * @return \Illuminate\Http\JsonResponse */ public function refresh() { return $this->createNewToken(auth()->refresh()); } /** * Get the authenticated User. * * @return \Illuminate\Http\JsonResponse */ public function userProfile() { return response()->json(auth()->user()); } /** * Get the token array structure. * * @param string $token * * @return \Illuminate\Http\JsonResponse */ protected function createNewToken($token){ return response()->json([ 'access_token' => $token, 'token_type' => 'bearer', 'expires_in' => auth()->factory()->getTTL() * 60, 'user' => auth()->user() ]); } } 路线: Route::group([ 'middleware' => ['api'], 'prefix' => 'auth' ], function ($router) { Route::post('/login', [AuthController::class, 'login']); Route::post('/register', [AuthController::class, 'register']); Route::post('/logout', [AuthController::class, 'logout']); Route::post('/refresh', [AuthController::class, 'refresh']); Route::get('/user-profile', [AuthController::class, 'userProfile']); 登录和注册正在运行 但是当我访问用户配置文件路由时出现此错误: Symfony\Component\Routing\Exception\RouteNotFoundException:路由 [登录] 未定义。在文件中 C:\wamp64\www\project endor\laravel ramework\src\Illuminate\Routing\UrlGenerator.php 420号线 如果某些用户使用以下方式登录,我无法获取用户的ID:auth()->user()->id auth.php 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'jwt', 'provider' => 'users', 'hash' => false, ], 'admin' => [ 'driver' => 'session', 'provider' => 'users', ], ], 型号: <?php namespace App\Models; use Illuminate\Contracts\Auth\MustVerifyEmail; #use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Tymon\JWTAuth\Contracts\JWTSubject; class User extends Authenticatable implements JWTSubject { #HasFactory, use Notifiable; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password', 'otp', 'user_verification_token', 'verified', 'token', 'email_verified_at' ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ]; public function getJWTIdentifier() { return $this->getKey(); } public function getJWTCustomClaims() { return []; } } 任何建议都将受到高度赞赏 谢谢 错误消息说没有名为“login”的路由 Route::post('/login', [AuthController::class, 'login'])->name('login');
这个文件是数据库所有字段的ID信息,去往一个Blade,我想要将一个ID信息输入到我发送给我的脸的同一面板Blade中。 DataGrid 类扩展了 DataSet { ...
我有一个“图像”字段,类型是文件,只需验证是否选择了图像,意味着它也可以为空。 我尝试过: 'avatar' => 'mimes:jpeg,jpg,png,gif|max:100000',但它也是
我正在使用 Laravel。我正在创建我的数据库和种子文件。 (不使用测试虚拟)当我启动终端进程时,我收到了缺少参数错误。 khazax@khz ~/Code/Laravel $ php artisa...
我是 Laravel 的新手。当我使用代码时,当我尝试从 Android 上的应用程序调用 API 时发现错误。 我真的很迷失,我什至不知道问题是什么。 我不
Laravel 5.2.14 出现 Duxet/RethinkDB 播种错误
我已经为此项目设置了 Homestead 的每个项目安装,因此我不会将 RethinkDB 添加到我的所有 Laravel 应用程序中。 我已经能够非常轻松地在 Homestead 中设置 RethinkDB,并迁移数据...