nizam0786

nizam0786

Birmingham

Member Since 2 Years Ago

Experience Points 23,480
Experience
Level
Lessons Completed 194
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

26 Sep
2 months ago

nizam0786 left a reply on Connected To A Database On Another Server?

its a phpmyadmin database do I create the user there?

nizam0786 started a new conversation Connected To A Database On Another Server?

Hi guys,

I am not very experienced when it comes to connecting to databases remotely on Laravel and wanted to ask is it possible to connect to a database on another server?

If yes, how would I connect to the database and also if there is security on the database what would I need to do in order to successfully connect to it.

Thanks in advance.

11 Jun
6 months ago

nizam0786 left a reply on How To Get Json Working In Browsers?

@tykus ok no problem, thank you for your help.

nizam0786 left a reply on How To Get Json Working In Browsers?

@tykus that worked.

but I had it working on windows without a chrome extension any ideas how I could do that so I can view it on safari also.

If not will just stick to chrome. Thanks

nizam0786 started a new conversation How To Get Json Working In Browsers?

Hi guys,

I have switched to a Macbook from Windows and now I am using Laravel Valet. I want to see a variable outputted in the view in json format however, the data is being outputted in plain text.

was wondering to I have to install something in order for it to work. I have tried and viewed it in both safari and chrome but both are returning the variable in plain text.

thanks in advance.

31 May
6 months ago

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

@arukomp @Vilfago thanks for you help could not have done it without you much appreciated.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

Done Finally :)


$passes =  DB::table('gtcPasses')
            ->select('gtcPasses.*', DB::Raw('(SELECT gtcpassesprocess.gtcPassesProcess_Status FROM gtcpassesprocess WHERE gtcpassesprocess.gtcPassesProcess_gtcPasses_ID = gtcPasses.gtcPasses_ID ORDER BY gtcpassesprocess.gtcPassesProcess_DateQueued DESC LIMIT 1) as latest_status'))
                ->havingRaw('latest_status = 300')
                ->get();

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

@Vilfago nope error again :(

(2/2) QueryException SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT (gtcpassesprocess.gtcPassesProcess_Status FROM gtcpassesprocess WHERE gtc' at line 1 (SQL: select gtcPasses.*, SELECT (gtcpassesprocess.gtcPassesProcess_Status FROM gtcpassesprocess WHERE gtcpassesprocess.gtcPassesProcess_gtcPasses_ID = gtcPasses.gtcPasses_ID ORDER BY gtcpassesprocess.gtcPassesProcess_DateQueued DESC LIMIT 1) as latest_status from gtcPasses having latest_status = 300)

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

@Vilfago its returning the following error:

(2/2) QueryException SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') as latest_status from gtcPasses having latest_status = 300' at line 1 (SQL: select gtcPasses.*, gtcPassesProcess.gtcPassesProcess_Status FROM gtcPassesProcess WHERE gtcPassesProcess.gtcPassesProcess_gtcPasses_ID = gtcPasses.gtcPasses_ID ORDER BY gtcPassesProcess.gtcPassesProcess_DateQueued DESC LIMIT 1) as latest_status from gtcPasses having latest_status = 300)

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

@himanshu-dhiman thanks for your reply however, tried that in the past what @arukomp works however, need to figure a way to right the query in Laravel.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

Just need to figure a way how to right it in Laravel/eloquent then hopefully it will working.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

YES! it worked but how shall I right it up in Laravel. Thank you so much this has been really draining.

The below are the actual names of the columns etc.. I was changing them to make it easier to read.


SELECT 
    gtcPasses.*, 
    (
        SELECT gtcpassesprocess.gtcPassesProcess_Status FROM gtcpassesprocess WHERE gtcpassesprocess.gtcPassesProcess_gtcPasses_ID = gtcPasses.gtcPasses_ID ORDER BY gtcpassesprocess.gtcPassesProcess_DateQueued DESC LIMIT 1
    ) as latest_status
FROM gtcpasses
HAVING latest_status = 300

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

Thanks for the reply @arukomp will look into it.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

The only alternative I can think of doing and going to implement, is having soft deletes for the processes.

So I wont need to do anything significant changes to the database only have to add the deleted_at and then that will allow me to filter only the current ones.

but the only thing is it will be time consuming soft deleting each process which is old.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

Hi @Cronix I agree but its an old database that I am working on and there isn't much flexibility on changing it at the moment unfortunately.

30 May
6 months ago

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

@Vilfago no problem thanks for you help will keep trying.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

Passes Table
  • id = 1
  • bus_route_id = 17
  • type = 5
  • id = 2
  • bus_route_id = 2
  • type = 1
  • id = 3
  • bus_route_id = 4
  • type = 1
Processes Table
  • id = 1
  • pass_id= 1
  • count= 1
  • status= 500
  • status= 20/01/2018
  • id = 2
  • pass_id= 1
  • count= 2
  • status= 300
  • status= 15/02/2018
  • id = 3
  • pass_id= 1
  • count= 3
  • status= 100
  • status= 10/05/2018
  • id = 4
  • pass_id= 2
  • count= 1
  • status= 300
  • status= 14/01/2018
  • id = 5
  • pass_id= 3
  • count= 1
  • status= 300
  • status= 08/05/2018

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

Passes Table
id ------------- bus_route_id ------------- type 1 ------------- 17 ------------- 5 2 ------------- 2 ------------- 1 3 ------------- 4 ------------- 1
Processes Table
id ---- pass id ---- count ---- status ---- dateQueued 1 ---- 1 ---- 1 ---- 500 ---- 20/01/2018 2 ---- 1 ---- 2 ---- 300 ---- 15/02/2018 3 ---- 1 ---- 3 ---- 100 ---- 10/05/2018 4 ---- 2 ---- 1 ---- 300 ---- 14/01/2018 5 ---- 3 ---- 1 ---- 300 ---- 8/05/2018

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

Yes Status is in the processes table its a column.

Unfortunately I am working on an existing database so I can't really change much on it.

what would be the best way of sharing a concrete example?

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

No there isn't and 'is_active' column but there is a 'count' column so:

Count = 1 for the first print Count = 2 lost so reprinted Count = 3 current

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

Here you go:


select id, type, from passes where exists (select dateQueued from processes where passes.id = processes.pass_id and processes.deleted_at is null group by dateQueued having MAX(status) = 300) and passes.deleted_at is null

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

@Vilfago Sorry my bad... I changed it slightly let me change it back and send the sql query again. Sorry

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

Just want to make it clear that a pass can have many processes but a process belongs to only one pass.

processes basically just represent the whole process of a pass being purchased all the way to be printed and posted to customers.

A pass can have more than one process when a pass is lost, stolen etc... so we reprint the pass rather than creating another pass hence the reason it can have another processes.

When a new process is created the old process is still stored but the latest one is the most important.

Hope that helps understand what I am working with.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

@Vilfago yeah sure.

select id, type, from passes where exists (select status from processes where passes.id = processes.pass_id and processes.deleted_at is null group by status having status = 300) and passes.deleted_at is null

note: my variable names are different just renaming them to make it easy to understand.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

At the moment it just returns all passes with a process that has status == to 100.

I need the passes to be returned only if the 'latest' status is equal to 100.

hope that makes sense.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

@Vilfago Thanks for the reply again.... still returns a process which 'latest' status is not 100.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

I have tried the following but is only returning one pass? isn't there a way to use a join() in a whereHas() or another way to loop through the passes and join one process at a time.

 

$passes = Pass::select([ 'pass_id', 'type', 'process_status', ])->has('process')->join('processes', function ($join) { $join->on('passes.pass_id', '=', 'processes.process_pass_id') ->where('processes.date_queued', '=', DB::raw("(select max(date_queued) from processes)")); })->get();

nizam0786 left a reply on How To Join The Latest Object To Another Object.

This is what I have right now.


$passes = Pass::select([
            'id',
            'type',
            'process_status',
        ])->has('process')->join('processes', function ($query)
        {
            $query->on('passes.pass_id', '=', 'processes.process_pass_id')->latest('date_queued')->take(1);
        })->where('process_status', 300)->get();

select id, type, process_status from passes inner join processes on passes.pass_id = process.processes_process_pass_id where exists (select * from processes where passes.pass_id = processes.process_pass_id and processes.deleted_at is null) and process_status = 300 and passes.deleted_at is null

nizam0786 started a new conversation How To Join The Latest Object To Another Object.

Hi Guys,

I have a tables of passes and a table of processes. A pass has many processes.

I am trying to join only the latest process to the pass it belongs too.

I have currently attempted the following however, it is duplicating passes for every process that belongs to it.


$passes = Pass::select([ 'id', 'type', 'process_status', ])->has('processes')->join('processes', function ($query) { $query->on('passes.pass_id', '=', 'processes.proccess_pass_id'); })->get();

Thanks in advance.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

I think the only way to do it is joining the latest process and then checking the status of it.

if anyone knows how to do that please would appreciate the help.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

After doing raw queries in the database I kind of understand a bit better what is happening.

the query i was using was just checking to see if a process with status 300 exists return the pass which obviously was checking all processes rather than just the latest one.

So know I am getting the latest process but how would I check to see the status in the whereHas()?


$passes = Pass::select([
            'id',
        'type'
        ])->has('process')->whereHas('process', function ($query){
            return $query->latest('date_queued')->take(1);
//need to check the status of this process if it equals to 300 then return the pass      otherwise don't
        })->get();

Thanks in advance

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

I need to figure a way to say in the sql to only check the latest process belonging to the pass to see if its status is 300 rather than all of them hope that makes sense.

The raw sql is

select passes_id, id , type, from passes where exists (select * from processes where passes.passes_id = processes.processes_id and processes.deleted_at is null) and exists (select * from processes where passes.passes_id = processes.processes_pass_id and processes_status = 300 and processes.deleted_at is null order by processes_pass_id desc, created_at desc limit 1) and passes.deleted_at is null

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

@Vilfago it returned a

(2/2) QueryException SQLSTATE[42000]: Syntax error or access violation: 1140 In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'gtctesting.processes.passes_process_id'; this is incompatible with sql_mode=only_full_group_by

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

@Melodia thanks for the reply I have already tried latest() and first().

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

@Vilfago thanks for the reply will try that now.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

The raw sql is

select passes_id, id , type, from passes where exists (select * from processes where passes.passes_id = processes.processes_id and processes.deleted_at is null) and exists (select * from processes where passes.passes_id = processes.processes_pass_id and processes_status = ? and processes.deleted_at is null order by processes_pass_id desc, created_at desc limit 1) and passes.deleted_at is null

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

Hi @Cronix and @Vilfago I tried the suggestion still did not work because what @Vilfago explained thats not exactly whats happening my message above explains whats happening but I think a subquery so just looking into that.

24 May
6 months ago

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

Thanks guys will try it out and let you know.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

Sorry if i am not making alot of sense I am trying my best to explain.

each time a pass is created a process is created with it

1 pass & 1 process

then for example a customer has a pass but we need to reprint it for them there is a reprint function which then creates a new process which makes the previous processes invalid or not needed but I still need them for history.

whats happening is I have a page which lists all passes with status 'waiting to be posted' i.e. 100

I want to list all passes with that status on the page but some passes are being listed there which shouldn't be because the query is checking all processes and if 100 exist in an old one it will list that too.

I want it to only focus on the last entry on the most recent.

statuses I have are

  • 100
  • 200
  • 300
  • 400
  • 500

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

It still returns pass with process->status == 100 even after filtering it with latest() and take().

I want it to basically ignore the previous processes and just check the latest one for the status.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

@Cronix I tried that but it takes the one after checking checking where status is 100 I want it to take('1') and then perform the where() status is 100.

hope that makes sense.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

@JorickL but I need to get the Pass object so wouldn't it need to be outside the whereHas()...?

I did try it anyway didn't work.

Thanks

nizam0786 started a new conversation Retrieving Objects When Latest Process Has A Status Which Is Equal To *

Hi guys,

I have been trying multiple different things to get this working but just cannot seem to find a solution.

Basically the only way I can do it is the following and its too slow:


    $totalPasses
    $passes = Pass::has('process')->get();

    foreach ($passes as $pass)
    {
        if ($pass->latestStatus() == 100)
        {
            $totalPasses++;
        }
    }


 public function process()
    {
        return $this->hasMany('App\Models\PassProcess', 'pass_id');
    }
public function latestProcess()
{
    return $this->hasOne('App\Models\PassProcess', 'pass_id')->latest('date_queued');
}

Ideally I want to return the passes rather than $totalPasses.

I have been trying the following but just can't get it to work.


$passes = Pass::select([
            'id',
            'type',
        ])->has('process')->whereHas('process', function ($query){
            $query->latest()->where('status', 300);
        })->get();

Thanks.

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

Hi @JorickL thanks for your reply tried it but doesn't work it returns the following errror:

BadMethodCallException Call to undefined method Illuminate\Database\Query\Builder::last()

nizam0786 left a reply on Getting All Objects If The Latest Status Is E.g. '100'

@topvillas thanks for your reply what date would I put there?

Lets says they are 3 processes that belong to a pass and the dates are below:

  1. date: 20/04/2018
  2. date: 10/05/2018
  3. date: 18/05/2018

I just want to get the most recent process which would be number 3 above. Thanks

nizam0786 started a new conversation Getting All Objects If The Latest Status Is E.g. '100'

Hi Guys,

I have been stuck on this for a while and have re written the discussion so hopefully it makes sense and I can be helped.

I have the following two models: Pass Process

A pass has many processes each process represents every time a pass is printed for a customer so really the latest process is the most important.

I am trying to right a query which gets all passes with the latest process->status equalling to 100.

I can get all passes with a process that has a status that equals 100 but that's not what I want I just want the query to focus and look at the most recent process.

below code is what I have at the moment. Please help.


$passes = Pass::select([
            'id',
            'type',
        ])->whereHas('processes', function ($query){
            $query->where('status', 100);
        })->get();

Thanks in advance.

nizam0786 left a reply on Trying To Retrieve Objects When A Related Objects Has A Specific Status.

@martinbean I have been using whereHas() you can see it in the above code that is working and also orderByDesc() is but the final part is I just want to take the first row and see what the status is rather than all of the related objects.

Hope that makes sense. Thanks

nizam0786 left a reply on Trying To Retrieve Objects When A Related Objects Has A Specific Status.

Is there a way of maybe using take() method or limit()?