eloquent

Laravel chunk and delete

穿精又带淫゛_ 提交于 2019-12-24 22:33:50
问题 I have a large number of items (1M+) that i want to delete from a database, i fork a background job to take care of that, so that the user won't have to wait for it to finish to carry on whatever he/she was doing, the problem is, the app becomes unresponsive while the items are being deleted, so i thought that i would process the items chunk by chunk and sleep for a couple of seconds then carry on. Here is the code that handles the delete: // laravel job class // ... public function handle()

Laravel eloquent query on a relational table

对着背影说爱祢 提交于 2019-12-24 22:31:55
问题 i am fairly new to laravel eloquent and i am trying to write a nested query to get data of food and food of resturent I have two table one is 'food_list' which mainly contain 'title','type' Type is int 0/1, 0 means veg and 1 means non veg Another table i have resturent _food Which has restaurant_id, food_id,price, image Now i want to get food list of tge resturent which is only veg So i wrote a query like this RestaurantFood:with(['foodDetail'=>function($q){ $q->where('type',0);}])->where('id

How can I get the value of this variable?

无人久伴 提交于 2019-12-24 22:03:17
问题 In logout function, I need to get the value of $time. This variable was declared in other function, when user logged in. Broadcast::channel('chat', function ($user) { $ip = Request::ip(); $time = now(); if (auth()->check() && !session()->has('name')) { UserInfo::storeUser(); session()->put('name',$user->name); return [ 'id' => $user->id, 'ip' => $ip, 'name' => $user->name, 'joined' => $time, ]; } }); When user logged out, I have to check his 'id' and value of 'joined'. How can I do this?

Can I place two migration tables in different databases when using Laravel?

北城余情 提交于 2019-12-24 21:27:08
问题 Right now I am building few social networks each having its own domain and database called content and a single common user database that is connected to all of them. The question is - can I place the migration data concerning users into the users' database, so that every time updates to database are implemented via php artisan migrate on each of the social networks, - those would only apply to user database only once. 回答1: I have done this on a project in the past, but you need to be careful

Laravel Pagination View

 ̄綄美尐妖づ 提交于 2019-12-24 21:09:47
问题 Hi everyone, i have done the pagination coding, but the view couldn't call out, can someone guide me ? My (categoryController.php) : // $tmp = Category::all()->toArray(); $tmp = Category::where('code','like','%' .$codeSearch. '%')->where('description','like','%' .$codeSearch. '%')->paginate(5); $category = array(); foreach ($tmp as $key => $row) { $policy = Category::find($row['parent_id']); $tmpResult = new Category(); $tmpResult->id = $row['id']; $tmpResult->code = $row['code']; $tmpResult-

Error trying to output the Eloquent relationship in Laravel

戏子无情 提交于 2019-12-24 20:51:41
问题 I'm getting the error "Trying to get property 'company_name' of non-object". I studied about the Eloquent relationship and try to implement in my code. But it gives me that error in the view (products.show) Which part are wrong? Is it okay to have many different relationship to other model as well? In 'Vendor Model': public function getRouteKeyName() { return 'roc_no'; } public function user() { return $this->belongsTo('App\User'); } public function products() { return $this->hasMany('App

Cannot display related entities in one-to-many relationship

三世轮回 提交于 2019-12-24 19:14:38
问题 I have a one-to-many relationship in my code that I want to show on my view, but I get a NULL error. Below is the model with the defined relationship. public function products() { return $this->hasMany('App\Product', 'id', 'product_id'); } This is my controller method: $products = Invoice::with('products')->get(); return view('admin.invoices.show', compact('invoice', $invoice), compact('clients', $clients))->with(compact('products', $products)); This is my view, but it always displays no

updateExistingPivot() not working

独自空忆成欢 提交于 2019-12-24 18:22:06
问题 I'm trying to update a pivot table like this: public function updatePermission($id, $permissionId) { $permissionValue = Input::get('value'); $user = User::find($id); $perms = ['value' => $permissionValue]; $user->permissions()->updateExistingPivot($permissionId, $perms); } This pivot has been previously created with: public function attachPermission($id) { $permissionId = Input::get('id'); $permissionValue = Input::get('value'); $user = User::find($id); if (!$user->permissions->contains(

Laravel query builder SUM returns multiplied values

白昼怎懂夜的黑 提交于 2019-12-24 17:44:41
问题 I have the following query and been fighting with from yesterday after solving previous issue with the help of great stack-overflowers yesterday's question. $sales = DB::table('sales') ->leftJoin('store_configs', 'store_configs.id', '=', 'sales.store_config_id') ->leftJoin('category_sales', 'category_sales.sale_id', '=', 'sales.id') ->leftJoin('categories', 'categories.id', '=', 'category_sales.category_id') ->leftJoin('departments', 'departments.category_id', '=', 'categories.id') ->leftJoin

Can Laravel hasOne be used with belongsToMany?

天涯浪子 提交于 2019-12-24 17:28:27
问题 Let's say I have two tables: Users: id, name, country_id Countries: id, name Of course each user can only have one country , but each country is assigned to multiple users . So would it be safe to have a User model that utilizes hasOne and a Country model that uses belongsToMany method? Documentation makes it seem like you can't mix and match different types of relationships. 回答1: What you are describing is actually a One To Many relationship, where one country has many users. Your Country