Posts

Showing posts with the label laravel

Allowed memory size of 134217728 bytes exhausted (tried to allocate 81690624 bytes)

Allowed memory size of 134217728 bytes exhausted (tried to allocate 81690624 bytes) I tried to find an answer to this question, but nothing helped me yet. I have a helper function function a($id, $b = false) { $general = Feedbacks::join("bidders","bidders.id","=","feedbacks.bid_id") ->join("projects","bidders.project_id","=","projects.id") ->where([ "bidders.bidder_id" => $id, "bidders.status" => 2, "feedbacks.active" => 1, "bidders.active" => 1, "projects.active" => config("constant.project_done") ]) ->orderBy("feedbacks.created_at","DESC"); print_r($general);die; } For Controller side, I am getting the $id and passing it in this function. $id = Feedbacks::where('active',1)->get(['bid_id']); $rate = ...

One to Many to One relationship in laravel eloquent

One to Many to One relationship in laravel eloquent I have company , employee and motorCycle table. company employee motorCycle One Company has many employee. One employee has One motorCycle Company.php <?php namespace AppModel; use IlluminateDatabaseEloquentModel; class Company extends Model { protected $table = 'company'; protected $primaryKey = '_id'; public function employee() { return $this->hasMany(Employee::class); } } ?> Employee.php <?php namespace AppModel; use IlluminateDatabaseEloquentModel; class Employee extends Model { protected $table = 'employee'; protected $primaryKey = '_id'; public function motorCycle() { return $this->hasOne(MotorCycle::class, 'motorCycle', 'id'); } } ?> MotorCycle.php <?php namespace AppModel; use IlluminateDatabaseEloquentModel; class MotorCycle extends Model { protected $table = ...

Handling expired token in Laravel

Handling expired token in Laravel What is the best way to handle expired tokens in laravel 5. I mean I have a page and it has some links which perform ajax requests. They work fine when the page is loaded but when I wait for sometime then I get a TOKEN MISMATCH error. Now, I have to refresh the page to make it work again. BUT, I don't want to refresh the page. I want some way to refresh the token or some other work around to make it fix. I hope you got my point. are you using ajax or single page application? – UX Labs Jul 16 '15 at 9:49 i am using ajax. – Jamal Abdul Nasir Jul 16 '15 at 9:51 i'll post a work around ...

Fetching Data from another table using foreign key laravel

Image
Fetching Data from another table using foreign key laravel I have 2 tables attendance and student . I am trying to retrieve my stud_name from student table by using the student foreign key in attendance table. I have a controller that return the view of all the results from attendance model. I have also added the relationship in both student and attendance model but whenever i try accessing the view i got an error exception of Trying to get property 'stud_name' of non-object . Anyone able to help me? attendance student stud_name student student attendance attendance student attendance AttendanceController <?php namespace AppHttpControllers; use IlluminateHttpRequest; use AppAttendance; class GenerateReportController extends Controller { /** * Display a listing of the resource. * * @return IlluminateHttpResponse */ public function index() { $attendance = Attendance::with('student')->get(); return view('gen...

Lumen make:command

Lumen make:command I'm trying to execute code within my Lumen install via the command line. In full Laravel , I've read that you can use commands to achieve this via "make:command", but Lumen does not seem to support this command. Is there anyway to enable this command? Failing that, what's the best way of running code from the CLI in Lumen? Thanks Lumen does not have builtin Commands support – user1016265 Mar 1 '16 at 14:10 2 Answers 2 You can use the artisan CLI in Lumen as the same way as in Laravel but with fewer built-in commands. To see all built-in commands, use the php artisan command in Lumen. artisan php artisan Although there is no make:command command at Lumen, you can create your custom command: make:command Add ...

Multilevel relationship whereHas on eloquent Model in Laravel

Multilevel relationship whereHas on eloquent Model in Laravel I'd like to find Project::with('tasks.tags')->get(); Project::with('tasks.tags')->get(); where only projects with a particular id of tag return in the result set. For ex. I'd like to find a project with tasks and tasks with tags with only id of 1. In other words, filter the tasks return inside of the Project - Task relationship. I have tried various ways but have failed so far. I have tried: $project = Project::with('tasks.tags')->whereHas('tasks', function($query){ $query->whereHas('tags', function($query) { $query->where('id', 1); }); })->get(); And: $project = Project::with('tasks.tags')->whereHas('tasks', function($query){ $query->whereHas('tags', function($query) { $query->where('tag_id', 1); }); })->get(); This is how the re...