engrlaravel

engrlaravel

Member Since 1 Year Ago

Experience Points
4,700
Total
Experience

300 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
1
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
4,700 XP
Jul
10
1 month ago
Activity icon

Started a new Conversation Where Condition On HasMany Relationship

I have two tables

letters(Model Letter) and letter_users(Model LetterUser)

letter_users has letter_id & user_id.

I have below relationship

 public function users()
{
    return $this->hasMany('App\LetterUser', 'letter_id');
}

I want to select all letter for user_id=1. how this can be done?

Activity icon

Replied to Laravel: Apply Where Condition Based On Other Fields

@michaloravec what is $direction??? it is not variable, but database table field name.

Activity icon

Started a new Conversation Laravel: Apply Where Condition Based On Other Fields

I have below fields

direction,created_at,received_at

i need to apply where condition as below

if(direction == "IN")
 ->where('created_at,$date);
else
->where('received_at',$date);

how i can apply it in eloquent?

Note: direction field either has IN or OUT values in each row

Jun
19
1 month ago
Activity icon

Started a new Conversation Exclude Some Date Data In Laravel Eloquent

I have these queries

 $today_date = date('Y-m-d');

1- get today data

->whereDate('report_date', $today_date);

2- Last 7 days

->whereDate('report_date','>', Carbon::now()->subDays(7))

3- Last 30 days

->whereDate('report_date', '>', Carbon::now()->subDays(30))

I want to exclude today data from last 7 days data & exclide 1 & 2 data from last 30 days.

Also how to get data more than 30 days ?

May
21
2 months ago
Activity icon

Started a new Conversation Generate .ics Calendar File In Php Laravel

I want to generate a calendar file for meeting & send invitation for attendees, Is there any plugin or code in laravel?

what type of files should it support? and how to generate in php?

Activity icon

Started a new Conversation Attach Calendar With Email In Php

I have all meeting calendar data in database. I want to send invitation to user by email. Is there any way to generate and attach file/.ics file with email in laravel?

Activity icon

Started a new Conversation Multiple Timezone Issue In Laravel Application

I have one laravel application. my clients are in different timezones. I want to install separate application for them and set timezone for each one.

I will notify a user in which timezone he is. and will save all his time according to that timezone.

What is the best way to do it?

May
17
2 months ago
Activity icon

Replied to Beware # In .env Files

This saved alot of my time

Activity icon

Replied to Why Laravel Add @IP Address To Mysql Connection?

@snapey : I am really impressed. You saved my time. Password had #. it should be quoted. I never thought that could be the reason

Activity icon

Replied to Why Laravel Add @IP Address To Mysql Connection?

single quotes or double quotes?

"MYP#WD"

like this?

Activity icon

Started a new Conversation Why Laravel Add @IP Address To Mysql Connection?

Here is my connection

DB_HOST =--------
 DB_PORT=3306
 DB_DATABASE=mydb
 DB_USERNAME=root
 DB_PASSWORD=pwd

I can connect with mysql client like SQLYog but my laravel application can not connect. it saying

 Access denied for user 'root'@'47.......

why root become [email protected]?

I do not have access to db, so i need to remove ip

i am getting access denied error

May
09
3 months ago
Activity icon

Replied to Logical Mistake With Eloquent Query

For all people having this problem, it wont work.

   $today_cnt = $tasks_today->whereDate('due_date','=',date('Y-m-d H:i:s'))->count();
    $tomorrow_cnt = $tasks_tomorrow->whereDate('due_date','=',$tomorrow)->count();

    $week_count = $tasks_week->whereBetween('due_date', [Carbon::now()->startOfWeek(), 
    Carbon::now()->endOfWeek()])->count();

The problem is it cancatenate with previous conditions as well.

for example if you print

 $tomorrow_cnt = $tasks_tomorrow->whereDate('due_date','=',$tomorrow)->count();

it will have two due_date condition

Activity icon

Started a new Conversation How To Get Microsoft Team Meeting Url In Laravel?

I am developing meetings application in laravel. I want to get meeting url only from microsoft team application. Is there any help or api? i checked this one

  sebbmeyer

but i think it is not related to my question( it only send notifications to Microsoft Teams)

Activity icon

Replied to Logical Mistake With Eloquent Query

1- Yes, for safty purpose i added company id as well. 2- it should have users created tasks or tasks assigned to him.like all below task ids

$task_ids = TaskUser::where('user_id',$request->input('user_id'))->pluck('task_id')->all();

I am worried about his part, can we do like this?

       $tasks_today = $tasks;
        $tasks_tomorrow = $tasks;
        $tasks_week = $tasks;

then apply where conditions on individuals? is this correct approach? will it change or effect $tasks query string as well?

Activity icon

Started a new Conversation Logical Mistake With Eloquent Query

I have below query code but i am not getting correct result. Is there any logical mistake in my code?

$tasks = Task::where('deleted_at', null);
        $tasks = $tasks->where(function($q) use ($user_id,$company_id, $task_ids){
            $q->where(function($q2) use ($user_id,$company_id, $task_ids) {
                $q2->where('created_by',$user_id)
                    ->where('company_id',$company_id);
            })
                ->orWhereIn('id',$task_ids);
        });
        $tasks_today = $tasks;
        $tasks_tomorrow = $tasks;
        $tasks_week = $tasks;

        $tomorrow = date("Y-m-d", strtotime("+1 day"));
        $today_cnt = $tasks_today->whereDate('due_date','=',date('Y-m-d H:i:s'))->count();
        $tomorrow_cnt = $tasks_tomorrow->whereDate('due_date','=',$tomorrow)->count();

        $week_count = $tasks_week->whereBetween('due_date', [Carbon::now()->startOfWeek(), 
        Carbon::now()->endOfWeek()])->count();

        $due_result[] = array(
            'due_today' => $today_cnt,
            'due_tomorrow' => $tomorrow_cnt,
            'due_this_week'=>$week_count,
            'due_all'=>$tasks->count()
        );
May
06
3 months ago
Activity icon

Started a new Conversation Getting Third Level Data In Eloquent

I have Task Class and TaskTeam class. Task class has this function

public function teams()
{
    return $this->hasMany('App\TaskTeam', 'task_id');
}

And TaskTeam has below relation

public function team()
{
    return $this->belongsTo('App\Team');
}

Now each team has members, so i have below function in Team

public function members()
{
    return $this->hasMany('App\TeamMember', 'team_id');
}

Question: for a task how to find members directly?

May
04
3 months ago
Activity icon

Started a new Conversation Migrating MySQL To MS SQL With LARAVEL

I have developed application in LARAVEL 6 and MySQL. Now my client want to use MS SQL instead. I know i need to change

DB_CONNECTION=sqlsrv

What are all the problems i will face? what bugs & issues will come? Is it possible to use it smoothly? what are precautions?

May
01
3 months ago
Activity icon

Replied to Laravel Eloquent Query OR Problem

@all : Unfortunately this is not working, I am expecting a proper optimized query for laravel experts.

I want to apply all conditions on $task_ids as well

Apr
28
3 months ago
Activity icon

Replied to Laravel Eloquent Query OR Problem

@All: Is there any other better solution?

Activity icon

Replied to Laravel Eloquent Query OR Problem

@michaloravec : Now it will show deleted records for created_by by me. because deleted_at condition applied only on

id IN(...)

Activity icon

Replied to Laravel Eloquent Query OR Problem

@michaloravec : I want OR condition.

Example: select records which is created by me OR i am involved in that.

whole query is like this

        $tasks = Task::where('deleted_at', null)->where('company_id',$request->input('company_id'));
        $tasks = $tasks->where('created_by',$request->input('user_id'));
        $task_ids = TaskUser::where('user_id',$request->input('user_id'))->pluck('task_id')->all();
        $tasks = $tasks->orWhereIn('id',$task_ids);
Activity icon

Started a new Conversation Laravel Eloquent Query OR Problem

I have a query

$tasks = Task::where('deleted_at', null)->where('company_id',$company_id);
$tasks = $tasks->where('created_by',$user_id);
$tasks = $tasks->orWhereIn('id',$task_ids);

It generate below query

SELECT * FROM `tasks` WHERE `deleted_at` IS NULL AND  `company_id` = 25 AND `created_by` = 20 OR 
`id` IN(112,...215) ORDER BY `id` DESC

Now Id 112 is deleted but still showing in result, although i have where('deleted_at', null) condition but it is not working

how to apply that as well?

Apr
22
3 months ago
Activity icon

Started a new Conversation Laravel Eloquent Query Problem

My eloquent query generates below sql query

SELECT * FROM `tasks` WHERE `deleted_at` IS NULL AND  `company_id` = 25 AND `created_by` = 20 OR `id` IN(112,...215) ORDER BY `id` DESC

Query is here

$tasks = Task::where('deleted_at', null)->where('company_id',$company_id);
 $tasks = $tasks->where('created_by',$user_id);
 $tasks = $tasks->orWhereIn('id',$task_ids);

Now there is status fields in tasks table which has either 0 or 2 values. I want only to select status=2, BUT when i user

$tasks = $tasks->where('status',0)

It give me wrong result. the real data is TOTAL Records=30, Status=2 records = 9, Status=1 records are 21.

where is the problem in my query

Apr
17
3 months ago
Activity icon

Replied to Laravel Validation With Jquery/javascript FormData

Commenting these two line give error in jquery file

Uncaught TypeError: Illegal invocation
Activity icon

Replied to Laravel Validation With Jquery/javascript FormData

Request payload showing data

Content-Disposition: form-data; name="title"

and its value

Activity icon

Replied to Laravel Validation With Jquery/javascript FormData

Validation error

{"status":"false","message":{"title":["The title field is required."],"user_id":["The user id field is required."],"company_id":["The company id field is required."]},"code":400,"result":""}
Activity icon

Replied to Laravel Validation With Jquery/javascript FormData

@scooby : I already tried it, this is not the problem. It is working in POSTMAN

Activity icon

Started a new Conversation Laravel Validation With Jquery/javascript FormData

I have below code

 var FD = new FormData();    
    FD.append( 'title', "my title" );
    FD.append( 'user_id', "20" );
    FD.append( 'company_id', "30" );

$.ajax(
{
beforeSend: function (xhr) {
                xhr.setRequestHeader('Authorization', 'Bearer bdea4988dcc54bd6b54e5c914512fbd137499e44be52786e05d38d75e701abc7');
                xhr.setRequestHeader('Accept', 'application/json');
                xhr.setRequestHeader('Content-Type', 'application/json');
                },
  url: 'http://localhost/myappl/public/api/eob/test_team',
 data: FD,
 dataType: "JSON",
 processData: false,
contentType: false,
type: 'POST',
success: function(data){
 alert(data);
 }
 });



$validator = validator::make($request->all(), [
        'title'     => 'required',
        'user_id' => 'required',
        'company_id'=>'required',

    ]);

    if ($validator->fails()) {
        return response()->json([
            'status'=>'false',
            'message'=>$validator->errors(),
            'code'=>400,
            'result'=>''
        ], 400);
    }

it give me validation error

Apr
12
4 months ago
Activity icon

Replied to Apply Where Condition Based On Value In Table Column

@snapey : Because I want to get a specific record. For example I want to get result id=5.

Now i need to check, If it template_type = system then Ok get it BUT if template_type= user then check if it is created_by me (this is my own data?), if not then do not show result and tell user "Not Found"

Activity icon

Replied to Where Condition On One To Many In Laravel Eloquent

@povilaskorop It worked with little bit modifications

 $teams = Team::where('company_id',$company_id)->where('created_by',$user_id)->whereNull('deleted_at')
            ->orWhereHas('members', function($query) use ($user_id){
                return $query->where('user_id', $user_id);
            })
            ->orderBy('id', 'DESC')->get();
Activity icon

Replied to Apply Where Condition Based On Value In Table Column

@snapey : my ID is unique and primary key.

Note: I have one field template_type which has two values (system , user).

I want to select all record where template_type = system, also if template_type = user then only select those records which is created_by me. some thing like this

if(template_type = 'user')
{
   $query->where('created_by',$request->input('user_id'))
}
Activity icon

Replied to Where Condition On One To Many In Laravel Eloquent

Hi,

Sorry for misunderstanding, But i want to select this result with one query.

I think we should use OR condition.

Criteria: all teams which i created or i am member of any team

Apr
11
4 months ago
Activity icon

Started a new Conversation Where Condition On One To Many In Laravel Eloquent

I have one table teams & other table team_members

 teams(id,title, created_by)
 team_members(id,team_id,user_id)

Team.php model has below function

 public function members()
 {
     return $this->hasMany('App\TeamMember', 'team_id');
  }

TeamMember.php model has below functions

 public function member()
 {
    return $this->belongsTo('App\User');
 }

 public function team()
 {
    return $this->belongsTo('App\Team');
 }

If i am login, i want to select all teams created_by me or teams i am member of.

In other words, Assume my id is 10, so select

1- teams.created_by = 10

2- team_members.user_id=10

how i can get this by laravel eloquent with one query?

Activity icon

Replied to Apply Where Condition Based On Value In Table Column

@ALL: Does anyone have a solution for this? I am waiting for whole community to answer this question.

Apr
10
4 months ago
Activity icon

Replied to Apply Where Condition Based On Value In Table Column

@bezhansalleh : This is not working, I guess because there is no IF condition. It apply on all.

Activity icon

Replied to Apply Where Condition Based On Value In Table Column

@bezhansalleh : I have below code, but i am getting error

$template = ReportTemplate::where('deleted_at', null)
            ->where('id',$request->input('template_id'))
            ->where(function($query) use ($request) {
                if ($query->template_type == 'user') {
                    return $query->where('created_by',$request->input('user_id'));
                }
            })->where('company_id',$request->input('company_id'))->first();

error is

 "Property [template_type] does not exist on the Eloquent builder instance.",

although i have template_type in table.

Activity icon

Replied to Apply Where Condition Based On Value In Table Column

@usmanbasharmal : type is not variable. it is field name in mysql table

Apr
09
4 months ago
Activity icon

Started a new Conversation Apply Where Condition Based On Value In Table Column

I have below query

           $template = ReportTemplate::where('deleted_at', null)
            ->where('id',$request->input('template_id'))
            ->where('created_by',$request->input('user_id'))
            ->where('company_id',$request->input('company_id'))->first();

I want to apply ->where('created_by',$request->input('user_id')) only if type=1 .

where type is a field in table with 0 & 1 values.

how i can do it?

Apr
08
4 months ago
Activity icon

Started a new Conversation Send Email To Multiple Users In Loop

Hi have below code, i am using to send email to one user, How i can send it to multiple users?

Do i need to clear it after sending to one user?

foreach ($task->users as $user)
{
 $subject = $user->subject;
 $email = $user->email;
 $template_data = "any text";
  Mail::send([], [],
                        function ($message) use ($subject,$email,$template_data) {
                            $message->to($email)
                                ->from('[email protected]')
                                ->subject($subject)
                                ->setBody($template_data, 'text/html');
                        });
}
Apr
05
4 months ago
Activity icon

Replied to Laravel Scheduling Or Task Scheduling

@snapey : How i can create the job first in laravel? i guess there are many ways to do but i am not sure which one is best

Mar
31
4 months ago
Activity icon

Replied to Laravel Scheduling Or Task Scheduling

this will not work, is there any alternative?

Activity icon

Replied to Select All Records Where Due_date = Tomorrow

@snapey @jeffreyvanrossum : Thank you for your reply, I am confused about this

echo Carbon::tomorrow();   //2020-04-01 00:00:00

so Carbon::tomorrow(); print with time also. will it effect my result? what if it print 2020-04-01 01:00:00

then ??

Mar
30
4 months ago
Activity icon

Replied to Select All Records Where Due_date = Tomorrow

@snapey : Yes due_date = "2020-03-31 02:05:50". I mean expiring tomorrow.

Basically, i want to send reminder to users that your deal is expiring tomorrow to be remind.

It will be better if my query ignore time part of where condition

Activity icon

Started a new Conversation Select All Records Where Due_date = Tomorrow

I want to select all records who is expiring tomorrow. I have due_date (Y-m-d H:i:s) format,

   $tasks = Task::where('deleted_at', null)
        ->where('due_date', '>=', Carbon::tomorrow())->get();

i tried this but it will not work.

It should be irrespective of time.

Activity icon

Started a new Conversation Laravel Scheduling Or Task Scheduling

I want to send emails on expiry dates data in table. I want to run scheduler every five minutes.

I am using Windows Server for my website, so i can not use this command

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

what is alternative i can use?

Mar
26
4 months ago
Activity icon

Started a new Conversation Laravel Eloquent Problem

I have below query

 $tasks = Task::where('deleted_at', null)->where('status',0);
 $tasks = $tasks->orWhereIn('id',$task_ids);

Generated query

 SELECT * FROM `tasks` WHERE `deleted_at` IS NULL AND `status` = 0 OR `id` IN (80,101,107,112,113,133,134,184) ORDER BY `id`
  DESC

Problem is there are some task ids (113,133,134) who status =2. I want only to get all records of status =0 even it is IN condition.

Mar
24
4 months ago
Activity icon

Started a new Conversation Running Scheduling Tasks In Laravel On Windows Server

How to create cron jobs or schedule tasks on windows server?

I want to run a script/function every minute, what is best option?

Mar
07
5 months ago
Activity icon

Replied to How To Find Top Most Parent?

It do not help as it is not for multi level children, is there anything in laravel relationship or loop to get it?

Activity icon

Started a new Conversation How To Find Top Most Parent?

I want to get the only one Top most parent for any record. Here is my code

id  | cat_name      | cat_parent_id
 --- | --------------| ------------- 
1   | Parent Cat 1  | NULL 
2   | Parent Cat 2  | NULL 
3   | Child Cat 1   | 2 
4   | Child Cat 2   | 2 
5   | Parent Cat 3  | NULL 
6   | Child Cat 3   | 5
7   | Child-Child Cat 2 | 4


Parent Cat 1
Parent Cat 2
    Child Cat 1
    Child Cat 2
       Child-Child Cat 2
Parent Cat 3
    Child Cat 3


 public function parent() {
  return $this->belongsToOne(static::class, 'cat_parent_id');
}


  public function children() {
    return $this->hasMany(static::class, 'cat_parent_id')->orderBy('cat_name', 'asc');
  }

So for Child-Child Cat 2 , I want to get Child Cat 2

Example

FindTopParentId(7)  // so it will return me 2
Feb
24
5 months ago
Activity icon

Started a new Conversation Laravel- Eloquent: Find Nth Level Children

I want to find un-limited children for a parent in same table, here is my code

Note: I will pass one Id to find all its inner children. For example FindChildren(2)

id  | cat_name      | cat_parent_id
--- | --------------| ------------- 
1   | Parent Cat 1  | NULL 
2   | Parent Cat 2  | NULL 
3   | Child Cat 1   | 2 
4   | Child Cat 2   | 2 
5   | Parent Cat 3  | NULL 
6   | Child Cat 3   | 5
7   | Child-Child Cat 2 | 4


Parent Cat 1
Parent Cat 2
    Child Cat 1
    Child Cat 2
        Child-Child Cat 2
Parent Cat 3
    Child Cat 3


    public function parent() {
      return $this->belongsToOne(static::class, 'cat_parent_id');
    }

  //each category might have multiple children
    public function children() {
        return $this->hasMany(static::class, 'cat_parent_id')->orderBy('cat_name', 'asc');
    }