gouseferoz

gouseferoz

Member Since 5 Months Ago

Experience Points 1,270
Experience Level 1

3,730 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 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 Apr
3 weeks ago

gouseferoz left a reply on "SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row

@MKBAT - That solves the problem.

I had few rows of data in data_text which has the **module_data.id **

and that id is not present in module_data.

25 Apr
3 weeks ago

gouseferoz left a reply on "SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row

@staudenmeir

Module Data Migration:

public function up()
    {
        Schema::create('module_data', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->unsignedInteger('module_id');
            $table->timestamps();
            $table->foreign('module_id')->references('id')->on('modules')->onDelete('cascade');
        });
    }

Modules Migration:

public function up()
    {
        Schema::create('modules', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->unsignedInteger('user_id');
            $table->timestamps();
        });
    }

gouseferoz started a new conversation "SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row

I have a table without any foreign key in it and i want to add a foreign key to have onDelete('cascade') between two tables.

public function up()
    {
        Schema::create('data_text', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id');
        $table->unsignedInteger('chapter');
            $table->string('data')->nullable();    
            $table->timestamps();
    });
    }

and my new migration is

public function up()
    {
        Schema::table('data_text', function (Blueprint $table) {
            $table->foreign('chapter')->references('id')->on('module_data')->onDelete('cascade');
        });

    }

while migrating, i am getting the following error

Exception trace:

  1   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`in
stacks`.`#sql-d0_13b`, CONSTRAINT `data_text_chapter_foreign` FOREIGN KEY (`chapter`) REFERENCES `module_data` (`id`) ON DELETE CASCADE)")
      C:\xampp\htdocs\Instacks\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:119

  2   PDOException::("SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`instacks`.`#sql-d0_13b`
, CONSTRAINT `data_text_chapter_foreign` FOREIGN KEY (`chapter`) REFERENCES `module_data` (`id`) ON DELETE CASCADE)")
      C:\xampp\htdocs\Instacks\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:117

can anyone help me whats issue happening here?

Regards, Feroz

22 Apr
3 weeks ago

gouseferoz started a new conversation How To Have A Image Preview In The Light Box For Before Uploading In The Form

I am uploading images using the form however i wanted to see the preview of the image while uploading it.

I was able to achieve using that using jquery render, but the image sizes are small and i cannot display the whole image of its size on the page. So i thought of using lightbox.

I am using lightcase javascript library. When i use the below javascript code, I am getting 404 error in the popup where the image has to be loaded.

//HTML file
              <a id="questionImage" data-rel="lightcase">Preview</a>


//Jquery
$('body').on('change', '.imagepreview', function() {
    $imageid = $(this).attr('data-img');
    if (this.files && this.files[0]) {
    var reader = new FileReader();

    reader.onload = function (e) {
    // var image = new Image();
    // image.src = e.target.result;
      $("#"+$imageid).attr('href', e.target.result);
    };
    reader.readAsDataURL(this.files[0]);
  }
});

can anyone suggest what is the better approach for this?

Regards, Feroz.

08 Apr
1 month ago

gouseferoz left a reply on My Server Is Not Loading The Latest Files.

@KEVINC - no, i am not using any caching

07 Apr
1 month ago

gouseferoz left a reply on My Server Is Not Loading The Latest Files.

@SNAPEY - no i dont have any caching service.

However i renamed the view file and used the new file and it worked.

Not sure what is the root cause of it.

I did clear the view using artisan clear:view , it didnt work though

gouseferoz left a reply on My Server Is Not Loading The Latest Files.

@JLRDW - I did clear cache using php artisan cache:clear. But its of no use

06 Apr
1 month ago

gouseferoz started a new conversation My Server Is Not Loading The Latest Files.

Hey Guys,

I have a website on nginx server and today it is loading old content instead of new content.

I have checked the server and the content is new there. Dont know why it is behaving like this. It was alright till the evening.

Can any help me whats going on?

Regards,

29 Mar
1 month ago

gouseferoz left a reply on Foreign Key Constraint Incorrectly Formed.

@snapey when I ran the module_para first and then module_text later, I don't see this error.

gouseferoz left a reply on Foreign Key Constraint Incorrectly Formed.

@SNAPEY - First module_text is migrating and throwing error Foreign key constraint error.

Do I need to migrate module_para first?

28 Mar
1 month ago

gouseferoz started a new conversation Foreign Key Constraint Incorrectly Formed.

I am trying to add a foreign key cascade in migrations and for some reasons it is not working.

I tried to find the issue but no luck.

Schema::create('module_para', function (Blueprint $table) {
            $table->increments('id');
            $table->longText('module');
            $table->string('difficulty');
            $table->timestamps();
        });
Schema::create('module_text', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger("para_id")->default(0);
            $table->longText('explanation')->nullable();
            $table->timestamps();
            $table->foreign('para_id')->references('id')->on('module_para')->onDelete('cascade');
        });

Can you help me in resolving this issue?

24 Mar
1 month ago

gouseferoz started a new conversation Catching Exceptions While Importing An Excel File Using Maatwebsite

Hi Guys,

I am using maatwebsite to import the excel file and save the records in the database.

I was able to import them but I also want to add validations such as required|email and also want to catch the sql exceptions raised in between.

Below is my controller code.

public function import(Request $request)
    {
        $validateData = $request->validate([
            'class_id' => 'required'
        ]);
        try {
    $import->import(request()->file('usersExcel'), null , \Maatwebsite\Excel\Excel::XLSX);
    } catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
         $failures = $e->failures();
         $errormessage = "";
         dd($failures);
         foreach ($failures as $failure) {
             $errormess = "";
             foreach($failure->errors() as $error)
             {
                 $errormess = $errormess.$error;
             }
             $errormessage = $errormessage." ,\n At Row ".$failure->row().", ".$errormess."<br>";
         }
         return redirect('/create_users')->with('error', $errormessage);

    }

    }

Here is the import code:

use Importable, SkipsErrors;
    private $classid = 0;
    public function __construct(int $classid)
    {
        $this->classid = $classid;
    }

    public function model(array $row)
    {

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

    public function rules(): array
    {
    return [
        'name' => 'required',
        'email' => 'required',
        'password' => 'required',
    ];
    }

My roadblocks here are, i can catch the row validations and send that to the view through the controller but not sure whether this is right code. And I am not able to handle the queryExceptions that i get if i insert duplicate record.

Can you guys help me figuring it out.

11 Mar
2 months ago

gouseferoz left a reply on Data From A Table Where Column 1 Equals To Column 2 Of The Same Row

@snapey whereColumn also works and I am using whereColumn instead of whereRaw as it make the code more readable.

08 Mar
2 months ago

gouseferoz started a new conversation Data From A Table Where Column 1 Equals To Column 2 Of The Same Row

Hi All,

I was trying to pull the data from a table where column 1 equals to column 2 of the same row.

I was using something like this,

Posts::where("name","<=>","author")->get();

but the above query is returning null.

Can you help me what i was doing wrong.

21 Feb
2 months ago

gouseferoz left a reply on Configuring Phpmyadmin On Nginx Server For Laravel

Thanks @cronix for the help.

I am moving forward by using remote mysql connections rather than having phpmyadmin on the server. The HeidiSql does exactly the work I need.

Again, Thanks for your help.

gouseferoz left a reply on Configuring Phpmyadmin On Nginx Server For Laravel

It is just to view the data in my database.

The above link is apache server but i am using Nginx server, I am not sure if there will be some difference in both servers configs.

20 Feb
2 months ago

gouseferoz started a new conversation Configuring Phpmyadmin On Nginx Server For Laravel

Hey Guys,

I was trying to configure phpmyadmin for my laravel application on nginx server.

After installing, i can see my phpmyadmin on /var/www/laravel/phpmyadmin

When i am doing domain/phpmyadmin, i am getting 404 error. This may be due to the routing.

How can i overcome this and point out the phpmyadmin with the url.

I appreciate your help.

Regards, Feroz.

18 Feb
3 months ago

gouseferoz left a reply on Unable To Connect To Database In Linux Server.

I have found workaround to my issue.

I have created another user in mysql and granted all permissions to it. When i use this username in my env file, I was able to connect to the db.

gouseferoz left a reply on Unable To Connect To Database In Linux Server.

even i have hard coded the values in database.php, but they are not working.

gouseferoz left a reply on Unable To Connect To Database In Linux Server.

I have done those, everything looks ok for me. The database.php is using the env variables .

If there is a problem with those, tinker wouldn't work right !!

17 Feb
3 months ago

gouseferoz started a new conversation Unable To Connect To Database In Linux Server.

I have just moved my project to a vps server and made changes to all my files.

The only problem i am facing is unable to connect to the database.

SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'

my env file:


DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=instacks
DB_USERNAME=root
DB_PASSWORD=123456

I tried using tinker and I was able to save data into the tables. I was also able to migrate my tables.

But is unable to connect to the databases when trying to load something from db onto the page.

Is there anything i am missing?

Regards, Feroz.

16 Feb
3 months ago

gouseferoz left a reply on Using Queries In Blade Templates

@TYKUS - Thanks @tykus for your help here. I will try and see if that works.

gouseferoz left a reply on Using Queries In Blade Templates

@TYKUS - Sure thing.

Actuallly I am creating an exam,

Every exam will have different Exam_models which are stored in exam_models table.

Each Exam_model will have exam chapters, which are stored in exam_chapters table

And there is another table called questions, where i have different questions based on chapters and I am displaying these questions in the view.

So when i select an exam, All the questions will be loaded exam_module wise in the view.

To do that I am using the below controller:


$exammodels = ExamModel::where('exam_id',$id['id'])->get();

        foreach($exammodels as $exammodel)
        {
            //$models = $exammodel['module_id'].",".$models;
            $models = ExamChapters::where('exam_id',$id['id'])->where('model_id',$exammodel['module_id'])->get();

            foreach($models as $model)
            {
                $questions = $model['question_ids'].",".$questions;
            }
        }
$questions_array = trim($questions, ',');
        $questions_array = explode(',',$questions_array);
        //dd($questions_array);
        foreach($questions_array as $question)
        {
            $questiondetails = $questiondetails.','.trim(TextQuestions::select('question','option_1','option_2','option_3','option_4','option_5')->where('id',$question)->get(),'[]');
            $questiondetails = trim($questiondetails,',');
        }

        return view('tests.writeExam', compact('');

In the view I should be sending the model details , questions in that respective model.

Apologies for my bad coding.

gouseferoz left a reply on Using Queries In Blade Templates

@EKRIST1 - The reason is the data differs based on post category and there are multiple tables from where i have to pull the data from. I am new to eloquent relationships :)

gouseferoz left a reply on Using Queries In Blade Templates

@JLRDW - Can you point out which concept i should be looking at. I am kind of confused there.

If you can put an example, I would really appreciate that.

gouseferoz started a new conversation Using Queries In Blade Templates

Hey Guys,

I am trying to use the queries in the blade template because I have to loop the data using other variable.

@foreach($postCategory as $postcat)
        <li>{{ $postcat}}</li>

{{ $posts= App\Posts::allPosts(postcat) }} //This will give all the posts for that postcategory

    @foreach($posts as $post)
        <h1>{{ $question->created_date}}</h1>
    @endforeach

@endforeach

I am not sure if this is a correct method to use.

The issue i am facing is, at the line $posts = App..... , it is not only calling all the data from the DB but also printing on to the page.

Can anyone help me to overcome this or suggest the recommended way to use in my above example.

Thanks in advance :)

Regards, Feroz.

18 Jan
4 months ago

gouseferoz left a reply on How To Update The Existing Laravel Project With The Latest Libraries.

@billriess installing through composer will automatically update the existing project with the sociallite?

gouseferoz started a new conversation How To Update The Existing Laravel Project With The Latest Libraries.

Hello Everyone,

I have created a project with the basic laravel libraries that comes out of the box. Today i learned that to have a social login, we can make use of socialite tool provided by laravel which can be installed via composer.

So, i want to add those libraries to my project so that i can make use of them.

Is there a way to update the existing project folder with these changes without losing the already created work?

I appreciate your help :)

Regards, Feroz.

14 Jan
4 months ago

gouseferoz left a reply on Using Parameters In The URL

@nakov , if i want to use something called name, like

?name="nakov"

using request->name will return the name?

gouseferoz started a new conversation Using Parameters In The URL

Hello Everyone,

This may seem simple but I am having trouble in figuring out how to use parameters in the URL.

I am familiar in using URLs like

http://localhost/test/1/create

, where 1 being the dynamic value and its associated route will be something like:

/test/{id}/create

But I want to use something like,

http://localhost/test/create?id=1

I tried searching google, but I didnt get the answer. It would be a great help if you can help me out here.

04 Jan
4 months ago

gouseferoz left a reply on Calling Functions Inside A Model In The Blade View

@realrandyallen what if i want to get the data using name parameter in the above case.

where('name',$name)->get() doesnt seems to work.

gouseferoz left a reply on Calling Functions Inside A Model In The Blade View

@realrandyallen Thanks for the solution.

When i use some query in the function, the returned data is in JSON format. But i want only the string here.

Like,

$modeloutput = ModelName::where('id',$module_id)->pluck('name');
return $modeloutput ;

This is giving the output as

["Chapter 1"]

But i need only Chapter 1

gouseferoz started a new conversation Calling Functions Inside A Model In The Blade View

I was trying to call a function inside a model from the blade view.

<td>{{ App\ExamModules::modulename() }}</td>

I am seeing an error: Non-static method App\ExamModules::modulename() should not be called statically

This is my function on the model

public function modulename()
    {
        return "hello";
    }

Can anyone help what i am doing wrong here?

Thanks.

02 Jan
4 months ago

gouseferoz left a reply on Unable To Pass The Auth() Values To The Create Function.

This is my whole code,

class ExamCategoriesController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth:admin,superadmin');
    }
    public function view()
    {
        return view('admin.examcategory');
    }
    public function create(Request $request)
    {
        $id = auth()->id();
        $role = auth()->user()->user_role;
        
        $validateData = $request->validate([
          'name' => 'required|min:3'
        ]);


        ExamCategory::create([
            'name' => request('name'),
            'user_role' => $role,
            'user_id' => $id,
            'description' => "None"
        ]);

        //$examcategories = ExamCategory::where('user_id',auth()->id())->get();

        return redirect('/superadmin/examcategory');
    }
}

gouseferoz started a new conversation Unable To Pass The Auth() Values To The Create Function.

I am passing the Auth()->id to the create function along with the other values.

But these values are not getting added and taking up only the default values passed that are used in the migrations.

public function create(Request $request)
    {
        $id = auth()->id();
        $role = auth()->user()->user_role;
        
        $validateData = $request->validate([
          'name' => 'required|min:3'
        ]);


        ExamCategory::create([
            'name' => request('name'),
            'user_role' => $role,
            'user_id' => $id,
            'description' => "None"
        ]);

        //$examcategories = ExamCategory::where('user_id',auth()->id())->get();

        return redirect('/superadmin/examcategory');
    }

What am i doing wrong here?

Regards, Feroz.

20 Dec
4 months ago

gouseferoz left a reply on Getting 500 Error Codes Instead Of 404 When Edited The Exception Handler File.

So looks like I found the solution for this.

use Illuminate\Auth\AuthenticationException; 

public function render($request, Exception $exception)
    {
        if($exception instanceof AuthenticationException){
            $guard = array_get($exception->guards(), 0);
            switch($guard){
                case 'admin':
                    return redirect('/admin/login');
                    break;
                default:
                    return redirect(route('login'));
                    break;
            }
        }
        return parent::render($request, $exception);
    }

Adding the AuthenticationException reference at the top

use Illuminate\Auth\AuthenticationException;

and adding a if condition solved the issue:

if($exception instanceof AuthenticationException){
19 Dec
5 months ago

gouseferoz left a reply on Getting 500 Error Codes Instead Of 404 When Edited The Exception Handler File.

These are the error i got:

[Wed Dec 19 20:38:43.175937 2018] [php7:error] [pid 5784:tid 1908] [client 127.0.0.1:51265] PHP Fatal error:  Uncaught Error: Call to undefined method Symfony\Component\Debug\Exception\FatalThrowableError::guards() in C:\xampp\htdocs\Instacks\app\Exceptions\Handler.php:49\nStack trace:\n#0 C:\xampp\htdocs\Instacks\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(112): App\Exceptions\Handler->render(Object(Illuminate\Http\Request), Object(Symfony\Component\Debug\Exception\FatalThrowableError))\n#1 C:\xampp\htdocs\Instacks\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(89): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse(Object(Symfony\Component\Debug\Exception\FatalThrowableError))\n#2 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\Debug\Exception\FatalThrowableError))\n#3 {main}\n  thrown in C:\xampp\htdocs\Instacks\app\Exceptions\Handler.php on line 49
[Wed Dec 19 20:38:43.175937 2018] [php7:error] [pid 5784:tid 1908] [client 127.0.0.1:51265] PHP Fatal error:  Uncaught Error: Call to undefined method Symfony\Component\Debug\Exception\FatalErrorException::guards() in C:\xampp\htdocs\Instacks\app\Exceptions\Handler.php:49\nStack trace:\n#0 C:\xampp\htdocs\Instacks\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(112): App\Exceptions\Handler->render(Object(Illuminate\Http\Request), Object(Symfony\Component\Debug\Exception\FatalErrorException))\n#1 C:\xampp\htdocs\Instacks\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(89): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse(Object(Symfony\Component\Debug\Exception\FatalErrorException))\n#2 C:\xampp\htdocs\Instacks\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(123): Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\Debug\Exception\FatalErrorException))\n#3 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown()\n#4 {main}\n  thrown in C:\xampp\htdocs\Instacks\app\Exceptions\Handler.php on line 49

The error in Handler.php is at this:

$guard = array_get($exception->guards(),0);

gouseferoz started a new conversation Handling The Routes

Hi All,

i have a route in web.php which is Tests. I can access the route using localhost/Tests to see the intended view. But if i do, localhost/tests, I am getting "500 Server cannot handle error".

As per the logic, it should throw 400 error page right.

Please let me know what i am missing?

Regards, Feroz

17 Dec
5 months ago

gouseferoz left a reply on Getting Data Using The Parameter From The Function.

return Exams::where('exam_category', $id['id')->get();

gouseferoz started a new conversation Getting Data Using The Parameter From The Function.

I have two tables exam and examcategory. I am trying to fetch all exams for a particular exam_category using: public function viewTests(ExamCategory $id) { return Exams::where('exam_category',$id); //return Exams::where('exam_category', $id); }

But it is returning : Object of class Illuminate\Database\Eloquent\Builder could not be converted to string error.

can anyone help me what i am doing wrong.

Regards, Feroz.