我有一个数据数组,我想在同一个数组中添加一个键和它的值.在这里,addedPost我想添加键favouritePost,它的值是$favouritePost在product键之后.我怎样才能做到这一点 ?
这是我的查询:
$addedPost = Post::with(['product','postattribute.attribute.category','user.userDetails'])
->whereId($postData['post_id'])
->first();
$favouritePost = PostFavourite::isAlreadyAdded($postData['post_id'], Auth::id());
return [
'status_code' => $status_code,
'message' => $message,
'PostDetails' => $addedPost
];
Run Code Online (Sandbox Code Playgroud)
我得到的回应是:
{
"PostDetails": {
"id": 289,
"user_id": 12,
"product_id": 2,
"demand_or_supply": "Demand",
"description": "edited1",
"status": "Expired",
"created_at": "2018-06-22 07:35:27",
"updated_at": "2018-07-05 06:42:56",
"product": {
"id": 2,
"title": "Diamond",
"icon": null,
"status": "Active"
}
}
}
Run Code Online (Sandbox Code Playgroud)
预期结果:
{
"PostDetails": {
"id": 289,
"user_id": 12,
"product_id": 2,
"demand_or_supply": "Demand",
"description": …Run Code Online (Sandbox Code Playgroud) 我在搜索连接表字段中的记录时遇到问题。我需要搜索所有列,包括连接表列。
这是我的所有州和国家/地区的控制器功能:
public function allStates()
{
$states = State::select(['id', 'country_id', 'state_type', 'state_code', 'state_name', 'status'])->orderBy('country_id','Asc');
return Datatables::of($states)
->addColumn('checkes', function ($states) {
$data = $states;
return view('partials.datatable.table_first_column_checkbox', compact('data'))->render();
})
->editColumn('country_id', function ($states) {
return $states->country ? $states->country->country_name : "N/A";
})
->editColumn('status', function ($states) {
$data = $states;
$statusChangeRoute = route('state.change.status');
return view('partials.datatable.status-switch', compact('data','statusChangeRoute'))->render();
})
->addColumn('action', function ($states) {
$editRoute = route('states.edit', $states->id);
$viewRoute = route('states.show', $states->id);
$controlKeyword = 'state';
return view('partials.datatable.table_edit_delete_action', compact('editRoute','viewRoute','controlKeyword'))->render();
})
->addColumn('DT_RowId', function ($states) {
return "tr_" . $states->id;
}) …Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的控制器并定义了一个函数.但是当我运行它时,它返回一个控制器不存在的错误.
在我的web.php中分配路由.
<?php
Route::get('/', function () { return view('front.welcome'); });
Route::get('plan','PlanController@PlanActivity')->name('plan');
Run Code Online (Sandbox Code Playgroud)
在我的控制器的另一边我的代码:
<?php
namespace App\Http\Controllers\Front;
use App\Http\Controllers\Controller as BaseController;
use Illuminate\Http\Request;
class PlanController extends Controller {
public function PlanActivity()
{
dd("hello");
//return view('admin.index');
}
}
Run Code Online (Sandbox Code Playgroud)
此控制器在App\Http\Controllers\Front上创建 - 在前端文件夹上
错误:
ReflectionException(-1)类App\Http\Controllers\PlanController不存在
laravel 上的第一个项目:当我要删除行时,它会抛出错误:SQLSTATE[23000]:完整性约束违规:1451 无法删除或更新父行:外键约束失败。我的控制器功能
public function delete(Request $request) {
try {
Venue::findOrFail($request->id)->delete();
} catch (\Exception $ex) {
return response()->json([
'error' => $ex->getCode(),
'message' => $ex->getMessage()
]);
}
return response()->json([
'message' => trans('admin.venue.delete_success')
]);
}
Run Code Online (Sandbox Code Playgroud)
模型 :
protected static function boot()
{
parent::boot();
self::deleting(function (Venue $venue) {
$venue->occasions()->delete();
$venue->contact()->delete();
$venue->gallery()->delete(); // here i am gtng error
$venue->venueParameter()->delete();
});
}
Run Code Online (Sandbox Code Playgroud)
详细错误:
SQLSTATE[23000]: 完整性约束冲突: 1451 无法删除或更新父行: 外键约束失败 (
red_carpet.media, CONSTRAINTmedia_gallery_id_foreignFOREIGN KEY (gallery_id) REFERENCESgalleries(id)) …
让我先显示我的代码。这是我的控制器功能代码
public function save(Request $request) {
try {
$this->validate($request, Venue::rules()); // Validation Rules
$venue = Venue::saveOrUpdate($request);
if($venue !== false) {
if($request->get('continue', false)) {
return redirect()->route('admin.venue.edit', ['id' => $venue->id])->with('success', trans('admin.venue.save_success'));
} else {
return redirect()->route('admin.venue.index')->with('success', trans('admin.venue.save_success'));
}
} else {
return back()->with('error', "Unable to save venue")->withInput();
}
} catch (\Exception $ex) {
return back()->with('error', "Unable to save venue")->withInput();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的模型功能代码
public static function rules($id = '') {
return [
'name' => 'required|string|max:255',
'logo' => 'required',
'status' => 'required|string|in:' . implode(",", …Run Code Online (Sandbox Code Playgroud) 我正在tymondesigns/jwt-auth为我的应用程序使用该包,但它token expired在一段时间后显示消息。我已经设置'ttl' => null并删除了exp但它没有用。
这是我的 config/jwt.php
<?php
/*
* This file is part of jwt-auth.
*
* (c) Sean Tymon <tymon148@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
/*
|--------------------------------------------------------------------------
| JWT Authentication Secret
|--------------------------------------------------------------------------
|
| Don't forget to set this in your .env file, as it will be used to sign
| …Run Code Online (Sandbox Code Playgroud) 我有简单的功能来重置我的密码。在我的函数中,对password值的最低要求是,1 digit但是当我尝试更新密码时它没有更新,当我6 digits输入密码时它工作正常。
我发现在vendor\laravel\framework\src\Illuminate\Auth\Passwords一个passwordBroker.php文件中有一个功能
protected function validatePasswordWithDefaults(array $credentials)
{
list($password, $confirm) = [
$credentials['password'],
$credentials['password_confirmation'],
];
return $password === $confirm && mb_strlen($password) >= 6; // here it is
}
Run Code Online (Sandbox Code Playgroud)
并且它包含验证($password) >= 6我如何删除它,当我更改此文件时它正在工作。在我的.gitignore vendor文件夹中未实时更新。解决办法是什么 ?如何覆盖此验证?
供参考这里是我的resetpassword功能
public function resetPassword(ResetPasswordRequest $request, JWTAuth $JWTAuth)
{
$validator = Validator::make($request->all(), User::resetPasswordRules());
if ($validator->fails()) {
return response()->json([
'message' => "422 Unprocessable Entity",
'errors' => $validator->messages(),
'status_code' => 422,
]);
} …Run Code Online (Sandbox Code Playgroud) 我很迷惑关于与搜索min-max值.在我的posts桌子上有一两场min_price和max_price,在我搜索有一对夫妇,我需要覆盖的搜索查询的事情.
如果用户仅搜索max_value,则显示所有价格为的帖子less than or equal to max_value.
如果用户仅搜索min_value,则显示所有价格为的帖子less than or equal to min_value.
如果用户使用min_value和搜索max_value,则显示所有价格介于两者之间的帖子min_value and max_value.
如果两者都为null,则返回所有帖子.
我怎样才能做到这一点 ?
我的代码:
$searchablePost = Post::with(['product','postattribute.attribute.category','user.userDetails'])
->whereIn('product_id', $userApprovalProductIDs)
->whereIn('demand_or_supply', $demand_or_supply);
// skip my search query code
$searchedPost = $searchablePost->offset($offset)->limit($limit)->orderBy('id','desc')->get();
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
在我的搜索中有$categroy_id - $country_id - $city_id. 有一张表activities具有所有这些价值。
我只是在我的控制器中实现了一个函数,但它返回了所有数据。
我的控制器功能代码:
public function PlanActivity(Request $request){
$category_id = $request->category_id;
$countryid = $request->country_id;
$cityid = $request->city_id;
$listactivity = Activity::all(); // get all activity
if($category_id != '') {
$listactivity->where('category_id', function ($query) use ($category_id) {
$query->where('category_id', $category_id);
});
}
return view('front.plan_activity',compact('listactivity'));
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我想将我的图像上传路径存储在表中。当前它返回
/storage/images/user/business_card/1524811791.jpg"
例如,我想存储完整的访问 URLabc.com/storage/images/user/business_card/1524811791.jpg
我怎样才能做到这一点 ?
图片上传代码:
if(Input::file('profile_picture'))
{
$profilepic = Input::file('profile_picture');
$filename = time() . '.' . $profilepic->getClientOriginalExtension();
$request->file('profile_picture')->storeAs('public/images/user/profile', $filename);
$accessUrl = Storage::url('images/user/profile'). '/' . $filename;
$url = Storage::put('public/user/profile/', $filename);
$saveUserInformation->profile_picture = $accessUrl;
$saveUserInformation->save();
}
Run Code Online (Sandbox Code Playgroud)