gouseferoz

gouseferoz

Member Since 11 Months Ago

Experience Points
2,690
Total
Experience

2,310 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
5
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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
2,690 XP
Nov
08
1 week ago
Activity icon

Replied to With() And Where() In Eager Loading

@griehle it is not returning any data and the console is showing content.js:21 Uncaught TypeError: Cannot read property 'tagName' of undefined

Activity icon

Started a new Conversation With() And Where() In Eager Loading

Hi,

I am trying to add relations and is confused with the implementation.

I have two tables, users and exams and i added some relations between two like the below code:

//User.pjp
public function exams()
    {
        return $this->hasMany(Exams::class);
    }
//Exams.php
public function user()
    {
        return $this->belongsTo(User::class);
    }

and trying to implement eager loading using the below code:

$exams = Exams::with('user')->get();
        $users = User::all();
        foreach($exams as $exam)
        {
            echo $exam->user;
        }

My requirement is , i want to select a particular exam from the Exams table based on the id but dont know how to implement it.

I need something like

public function showData($id)
    {
        $exams = Exams::with('user')->where('exam_id',$id)->get();
        $users = User::all();
        foreach($exams as $exam)
        {
            echo $exam->user;
        }
}

Can anyone help me how to do this?

Regards,

Activity icon

Replied to Running 2000 Queries Without Big Load On Server.

@chris-lw Can you give me an example of it?

and wouldnt make the sql query again?

Activity icon

Started a new Conversation Running 2000 Queries Without Big Load On Server.

Hi Guys,

I have a use case where i need to run like 2000 sql queries.

I am using the below code:


public function getresults($id){

$sortmarks = StudentExamTable::select('user_id','exam_id','exam_name','status')->where('exam_id',$id)->groupBy('user_id')->get();

$users = UserTable::select('id','name','email')->get();

foreach($sortmarks as $marks)
{
    $highest = StudentExamTable::where('user_id',$marks['user_id'])->where('exam_id',$id)->orderBy('total','desc')->orderBy('id','desc')->where('status','completed')->first();
    $marks->attempt_id = $highest['id'];
    $marks->ques_count = $highest['ques_count'];
    $marks->attempted_ques = $highest['attempted_ques'];
    $marks->positive = $highest['positive'];
    $marks->negative = $highest['negative'];
    $marks->total = $highest['total'];
    $marks->max_marks = $highest['max_marks'];
    $marks->percentage = $highest['percentage'];
    $marks->qualified = $highest['qualified'];
    $marks->created_at = $highest['created_at'];
    $marks->updated_at = $highest['updated_at'];
    $count = StudentExamTable::where('exam_id',$id)->where('user_id',$marks['user_id'])->count();
    $marks->attempted_count = $count;
    foreach($users as $user)
    {
        if($user['id'] == $marks['user_id'])
        {
            $marks->name = $user['name'];
            $marks->email = $user['email'];
        }
    }
}

}

if the first query has 2000 records then the code is going to make 2000+ SQL queries, can anyone help me optimize this code to make it run less sql queries?

Thanks in advance.

Nov
01
2 weeks ago
Activity icon

Replied to AJAX POST Request Issues In Live Environment

I think i found the issue.

In my code, i was using first() and count() like

$blogs = Posts::where('unique',$request['unique'])->first();
return count($blogs);

Instead, if i do this, the error goes away

$blogs = Posts::where('unique',$request['unique'])->count();
return $blogs;

I am not 100% sure whether this is the exact cause of the issue but with this change i am not getting the HTTP 500 error.

Oct
31
2 weeks ago
Activity icon

Replied to AJAX POST Request Issues In Live Environment

@jlrdw

I see the data but i am unable to perform the database queries later that in my code.

public function submit(Request $request)
{
    $posts = Posts::where('unique',$request['unique'])->get();
    return count($posts);
}

This wont work.

Activity icon

Replied to AJAX POST Request Issues In Live Environment

@jlrdw I got this from the developer's tools:

jquery-2.2.4.min.js:4 POST https://instacks.in/exam/submit 500
send @ jquery-2.2.4.min.js:4
ajax @ jquery-2.2.4.min.js:4
(anonymous) @ 1572548832:1612
dispatch @ jquery-2.2.4.min.js:3
r.handle @ jquery-2.2.4.min.js:3
Activity icon

Replied to AJAX POST Request Issues In Live Environment

@wafto I dont see anything in the logs except POST Internal Server 500 error.

Activity icon

Started a new Conversation AJAX POST Request Issues In Live Environment

Hello Everyone,

I am trying to implement a AJAX post request in my webpage.

I implemented in my local and its is working just fine but when i uploading the same code to live environment, it is giving the 500 error during post request.

I am not sure what is the issue. Can anyone help me out here.

Jquery Ajax Request

$.ajax({
           type:'POST',
           url:'/blog/submit',
           data:{
               unique: "{{ $uniqueID }}"
           },
           success:function(data){
              console.log(data);
           }
    });

Controller:

public function submit(Request $request)
{
    return $request;
}

The output i see on my console is:

/blog/submit: null
unique: "1572546628"

In my local, i dont see /blog/submit: null but in Live i can see that message.

Any thoughts?

Regards, Feroz.

Sep
27
1 month ago
Activity icon

Replied to Random Method In Eloquent.

I need ids to do something later in the project :)

If the first query shows some errors i will use the later.

Thanks for the help @snapey

Activity icon

Replied to Random Method In Eloquent.

So should I use like

Pages::inRandomOrder()->get()->take(30)->pluck('id');
``
Activity icon

Replied to Random Method In Eloquent.

@snapey It is working without adding get()

Pages::inRandomOrder()->take(30)->pluck('id');
Activity icon

Replied to Random Method In Eloquent.

@snapey thanks for the workaround and inRandomOrder() looks better than `random()'

However to get only a certain number of random records I used

inRandomOrder()->take(30)

Is this the right way of doing that? or is there any better way?

Please clarify.

Sep
26
1 month ago
Activity icon

Started a new Conversation Random Method In Eloquent.

Hi Guys,

I am using a random method to fetch the rows in a random manner. But i feel that random is not picking till the end of the table.

    $getPages = Pages::where('author','feroz')->get()->random(10)->pluck('id');

Is that so?

If yes, can you please suggest me how I can go till the last row of the table.

Regards, Feroz.

Activity icon

Replied to The Page Isnt Working Error

Well, count() has significantly reduced the time to get the data from the database.

Now I am not getting the 502 bad gateway error.

Thanks @wilk_randall

Sep
25
1 month ago
Activity icon

Replied to The Page Isnt Working Error

@munazzil i checked my code, and here is what i observed,

I am making a database query which has over 50000 rows just to get count of rows like:

$count1 = count(MyTable::where('role','user')->get());
$count2 = count(MyTable::where('role','author')->get());

and i am doing this 4 times each having different query parameter.

When i remove this block of code, the page works without any issue.

When i tried to save the direct result into the variable like

$data = Mytable::get();

I am getting 502 Bad Gateway on this page.

I dont know how to optimize this.

Can you help me with it?

Activity icon

Replied to The Page Isnt Working Error

Hey Guys,

Even after the change of the memory_limit,

I can still see the error

Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in
Sep
18
2 months ago
Activity icon

Replied to The Page Isnt Working Error

Any reason why this amount of memory being consumed by PHP?

Activity icon

Replied to The Page Isnt Working Error

Thanks for responding.

I checked the nginx server log and i see a memory issue :

Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /var/www/laravel/vendor/symfony/debug/Exception/FatalErrorException.php on line 0" while reading response header from upstream

This error is repetitive while accessing that particular page.

Any solution for this error?

Regards, Feroz.

Activity icon

Started a new Conversation The Page Isnt Working Error

Hey Guys,

I am having a laravel project in production and after logging in I see the error something like this:

This Page isnt working.
Site is unable to handle this request
HTTP ERROR 500

I have the APP_DEBUG=true in my .env file and even it is not displaying any other error details.

But after refreshing the page twice, i can see the data/page is being loaded without any issue.

Can anyone help me in resolving this error?

Regards, Feroz.

Aug
06
3 months ago
Activity icon

Replied to Passing Custom Variables To The Mail

Yes, I have removed the serializesModels from the Job, and now i can see the data.

Will removing this effect the mail?

Activity icon

Replied to Passing Custom Variables To The Mail

@talinon I have tried it and still i dont see any data here. When i tried priting the $user in the IssueJob, i see only the user details but not the explicitly added information.

Activity icon

Started a new Conversation Passing Custom Variables To The Mail

Hi,

I am trying to pass custom variables to the mail to the User record i.e., by adding few more parameters to the user record. But somehow those are not getting passed. Can you please help me out where the issue is happening.

Controller:

$issue = Issues::find(request('issue_id'));
$user = User::find($issue['user_id']);
$user->question_issue = $issue['issue'];
$user->issue_status = $issue['status'];
$user->issue_comment = $issue['comment'];
$question = Text::find($issue['ques_id']);
$user->question = $question['question'];
IssueJob::dispatch($user)->delay(now()->addSeconds(1));

IssueJob:

class IssueJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
     public $user;
     public function __construct($user)
     {
         $this->user = $user;
     }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Mail::to($this->user->email)->send(new IssuesMail($this->user));
    }
}

IssueMail:

class IssuesMail extends Mailable
{
    use Queueable, SerializesModels;

    public $user;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($user)
    {
        $this->user = $user;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->subject('Update on Issue')->view('mails.user.Issues');
    }
}

Mail Template:

<h2>Welcome to the Instacks {{ucwords($user['name'])}}</h2>
<br/>
<h2>Issue: {{ $user['question_issue'] }}</h2>
<h2>Question: {{ $user['question']}}</h2>
<h2>Status: {{ $user['issue_status'] }}</h3>
<h2>Comment: <br> {{ $user['issue_comment'] }}</h2>     

Except the name, other parameters are returning empty.

Can anyone help me here? I am not sure whether this is a right approach or not.

Regards, Feroz.

Jul
11
4 months ago
Activity icon

Replied to Get Data Without Column Names In Eloquent.

The data doesn't correlate here, I need to get data without the updated_at and total column names. The above thing is just an example.

Jul
10
4 months ago
Activity icon

Started a new Conversation Get Data Without Column Names In Eloquent.

I was trying to get data from db without column names so that i can pass them to the highcharts stocks like here: https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/stock/demo/basic-line/

When i am trying to get data, it is returning something in this format:

[
{
"updated_at": "2019-06-24 17:03:24",
"total": 0
},
{
"updated_at": "2019-06-24 17:39:12",
"total": 2
},
{
"updated_at": "2019-06-24 19:23:50",
"total": 2
},
{
"updated_at": "2019-06-24 19:25:30",
"total": 1
},

How can i get data into this format:

[
[
1499779800000,
145.53
],
[
1499866200000,
145.74
],
[
1499952600000,
147.77
],
[
1500039000000,
149.04
],

Regards, Feroz.

Jul
02
4 months ago
Activity icon

Replied to Elastic Email Is Not Working In Laravel

@SIANGBOON - I have checked the telnet and its working fine, I was able to send out a test mail.

After hardcoding the credentials, i was able to send the mails. I have to monitor these for a while. Dont know what might have caused the issue.

Jul
01
4 months ago
Activity icon

Replied to Elastic Email Is Not Working In Laravel

i will hard code the credentials into the mail.php file and see if that works.

Activity icon

Replied to User Is Not Able To Login When Created Data From Excel Upload

@SNAPEY - Looks like I need my coffee. I was trying with different password that what i provided in the file.

Thanks for pointing it out.

Activity icon

Replied to Elastic Email Is Not Working In Laravel

@SNAPEY - i did config('mail') and it matches what I intend to. And also checked the quotes around password.

The issue here is, when i trigger a mail, it is sending to mailtrap which i used for testing purpose but now i have replaced it with elastic mail credentials, but the mail is being received in mailtrap.

Activity icon

Replied to User Is Not Able To Login When Created Data From Excel Upload

@SNAPEY - I followed https://docs.laravel-excel.com/3.1/imports/basics.html this tutorial while working with excel imports.

Yes, I am giving everyone a password in the above case its 123456.

User Model si based off laravel user model and it extends Authenticable

Email and passwords are getting filled in the database.

Activity icon

Replied to User Is Not Able To Login When Created Data From Excel Upload

@TYKUS - It didnt work. Same error.

Does it have anything to do with remember_token cell in DB, 'cause it is empty for these type of records.

Activity icon

Replied to Elastic Email Is Not Working In Laravel

Looks like my .env is caching. The changes i am making to this file is not reflecting.

I tried to clear the cache using

php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan config:cache
php artisan route:cache
php artisan optimize

then i am getting this error

   LogicException  : Unable to prepare route [api/user] for serialization. Uses Closure.

  at /var/www/laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php:917
    913|      */
    914|     public function prepareForSerialization()
    915|     {
    916|         if ($this->action['uses'] instanceof Closure) {
  > 917|             throw new LogicException("Unable to prepare route [{$this->uri}] for serialization. Uses Closure.");
    918|         }
    919|
    920|         $this->compileRoute();
    921|

  Exception trace:

  1   Illuminate\Routing\Route::prepareForSerialization()
      /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/RouteCacheCommand.php:62

  2   Illuminate\Foundation\Console\RouteCacheCommand::handle()
      /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29

  Please use the argument -v to see more details.

How to solve this issue?

Activity icon

Started a new Conversation User Is Not Able To Login When Created Data From Excel Upload

I am creating users using by uploading user details using maatwebsite class. I can see the data being saved in database but when tried to login, I am unable to login.

User Import Class

public function model(array $row)
    {

        return new User([
           'name'     => ucwords($row['name']),
           'email'    => $row['email'],
           'password' => Hash::make('password'),
           'user_role' => 'student',
           'type' => 'indirect',
           'admin_id' => auth()->id(),
           'class_id' => $this->classid,
           'regd' => strtoupper($row['regd']),
           'email_verified' => true,
           'mobile' => $row['mobile']
        ]);
    }

When i register using the register page, I am able to login with that record.

Can anyone help me whats going wrong here?

Regards, Feroz.

Activity icon

Replied to Elastic Email Is Not Working In Laravel

@BOBBYBOUWMANN - Sure, how can I get the logs

Jun
30
4 months ago
Activity icon

Replied to Elastic Email Is Not Working In Laravel

i tried using some elastic mail wrappers too, but they are working in local but not in production. Can someone please help me here?

Activity icon

Replied to Elastic Email Is Not Working In Laravel

I used the same credentials in local environment and it was working fine without any issue.

The problem is with the production environment

Activity icon

Replied to Elastic Email Is Not Working In Laravel

@BOBBYBOUWMANN - i tried the above method but it didnt work, the API key and the password are the same in the elasticemail settings.

Jun
28
4 months ago
Activity icon

Started a new Conversation Elastic Email Is Not Working In Laravel

Hi,

I am using elastic email to send my emails. In local, i used mailtrap and it worked fine. I updated the .env file to use elastic mail credentials

MAIL_DRIVER=smtp
MAIL_HOST=smtp.elasticemail.com
MAIL_PORT=2525
MAIL_USERNAME=elasticmail_username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME=Laravel

Can anyone help me on this?

Regards, Feroz.

Jun
26
4 months ago
Activity icon

Replied to How To Fix Call To Undefined Method Illuminate\Session\Store::first() Error?

So, i found the issue why i am getting the above issue.

I used

@if(Session::has('error')
//Some Code here
@endif

If i remove this block, i dont see the issue. Why is that?

Jun
21
4 months ago
Activity icon

Replied to Is It Good To Use Queue In Laravel For Mails?

@DEANSATCH - sorry, i forgot to reread the file and start the supervisor again, i did it now and its working.

Thanks for the help.

Activity icon

Replied to Is It Good To Use Queue In Laravel For Mails?

@DEANSATCH - i did start the supervisor and also removed sqs, it didnt work.

Activity icon

Replied to Is It Good To Use Queue In Laravel For Mails?

@DEANSATCH - i have followed the supervisor installtion steps and configured it, and i dont see the queued jobs are getting executed. Am i doing anything wrong here?


[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/laravel/artisan queue:work sqs --sleep=3 --tries=3
autostart=true
autorestart=true
;user=forge
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/laravel/worker.log

This is my supervisor conf file.

Activity icon

Replied to Is It Good To Use Queue In Laravel For Mails?

I just ran queue:work in my server instance. When i kept the linux terminal open, it was working. But when i closed it, it didnt work.

I was using digitalocean server instance for my laravel app.

Activity icon

Started a new Conversation Is It Good To Use Queue In Laravel For Mails?

Hi Guys,

I am new to the concept of Queuing in Laravel, I have implemented a sample asynchronous Queue for the mails to trigger in my app. But to see the Queuing work, I need to run

php artisan queue:work

to process all the queued jobs. I see that this artisan command should be running everytime on the server to have the queue work. Is this correct?

Or is there any other workaround for not to run the artisan command and make Queue work.

What is the difference between Queue and Listen, Which is better to use?

Regards, Feroz

Jun
20
4 months ago
Activity icon

Replied to How To Fix Call To Undefined Method Illuminate\Session\Store::first() Error?

The issue is present even while submitting an empty form.

Activity icon

Started a new Conversation How To Fix Call To Undefined Method Illuminate\Session\Store::first() Error?

Hi,

I am trying to login into the laravel app using wrong password, which is giving

Call to undefined method Illuminate\Session\Store::first() 
C:\xampp\htdocs\Instacks\vendor\laravel\framework\src\Illuminate\Support\Manager.php
    /**
     * Get all of the created "drivers".
     *
     * @return array
     */
    public function getDrivers()
    {
        return $this->drivers;
    }
 
    /**
     * Dynamically call the default driver instance.
     *
     * @param  string  $method
     * @param  array   $parameters
     * @return mixed
     */
    public function __call($method, $parameters)
    {
        return $this->driver()->$method(...$parameters);
    }
}

How can i solve this issue?

Regards, Feroz.

Jun
18
5 months ago
Activity icon

Replied to Email With Dynamic Content From Controller.

@WILK_RANDALL - This works perfectly. Thanks for the quick help :)

Jun
11
5 months ago
Activity icon

Replied to Email With Dynamic Content From Controller.

@WILK_RANDALL - Thanks @wilk_randall , is it possible to provide an example. It would really help me.

Activity icon

Started a new Conversation Email With Dynamic Content From Controller.

Hi Guys,

I am trying to implement Emails for my laravel project, but dont know how to start.

I followed few tutorials out there and was able to trigger a mail.

I want to check how the I can send mails with dynamic data in its body which is pulled from the database.

Can anyone direct me to the right place which overlines these.

Regards, Feroz.