nizam0786

Experience

23,420

0 Best Reply Awards

  • Member Since 2 Years Ago
  • 194 Lessons Completed
  • 0 Favorites

11th June, 2018

nizam0786 left a reply on How To Get Json Working In Browsers? • 3 months ago

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

nizam0786 left a reply on How To Get Json Working In Browsers? • 3 months ago

@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? • 3 months ago

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.

31st May, 2018

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

@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' • 3 months ago

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' • 3 months ago

@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' • 3 months ago

@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' • 3 months ago

@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' • 3 months ago

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' • 3 months ago

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' • 3 months ago

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' • 3 months ago

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' • 3 months ago

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.

30th May, 2018

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

@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' • 3 months ago

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' • 3 months ago

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' • 3 months ago

ok no problem.

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

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' • 3 months ago

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' • 3 months ago

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' • 3 months ago

@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' • 3 months ago

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' • 3 months ago

@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' • 3 months ago

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' • 3 months ago

@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' • 3 months ago

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. • 3 months ago

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. • 3 months ago

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' • 3 months ago

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' • 3 months ago

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' • 3 months ago

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' • 3 months ago

@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' • 3 months ago

@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' • 3 months ago

@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' • 3 months ago

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' • 3 months ago

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.

24th May, 2018

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

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' • 3 months ago

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' • 3 months ago

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' • 3 months ago

@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' • 3 months ago

@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 * • 3 months ago

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' • 3 months ago

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' • 3 months ago

@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' • 3 months ago

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. • 3 months ago

@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. • 3 months ago

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

nizam0786 started a new conversation Trying To Retrieve Objects When A Related Objects Has A Specific Status. • 3 months ago

Hi guys,

I am trying to retrieve objects i.e. passes when its status is 300 i.e. 'waiting for authorisation'.

Objects: Pass Process

Pass has many Process.

Process has a column in the database which store the pass_status.

I want retrieve all passes when the latest process has a status of 'waiting for authorisation'


$passes = Pass::select([
                'gtcPasses_ID',
                'gtcPasses_gtcAcademicYears_ID',
                'gtcPasses_gtcTraveler_ID',
                'gtcPasses_gtcSchools_ID',
                'gtcPasses_gtcBusRoutes_ID',
                'gtcPasses_gtcPassType_ID',
            ])->has('process')->whereHas('process', function ($query){
                $query->where('gtcPassesProcess_Status', 300);
 });

The above code works when getting all passes with processes that have status 300 however, I am trying to only check the latest process rather than all processes.

I have a the following method in the pass model that retrieves the latest model.


public function latestProcess() { return $this->hasOne('App\Models\PassProcess', 'gtcPassesProcess_gtcPasses_ID')->latest('gtcPassesProcess_DateQueued'); }

if you need more information please let me know. Thanks in advance

nizam0786 left a reply on Trying To Count Related Object In Collection. • 3 months ago

@Snapey Thank you.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.