hassanshahzadaheer

hassanshahzadaheer

Member Since 1 Year Ago

karachi

Experience Points
8,000
Total
Experience

2,000 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
68
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 2
8,000 XP
Jul
27
2 months ago
Jul
25
2 months ago
Activity icon

Replied to This Action Is Unauthorized. For All User Except User Have Id Of 2

is there any other way to solve this error?

Activity icon

Replied to This Action Is Unauthorized. For All User Except User Have Id Of 2

nothing gets to change my bro, Don't know why it's happen

Activity icon

Replied to This Action Is Unauthorized. For All User Except User Have Id Of 2

like this ?

  public function boot(Gate $gate)
    {
        $this->registerPolicies();

        $gate->before(function ($user) {
            return $user->id;
        });
    }
Activity icon

Replied to This Action Is Unauthorized. For All User Except User Have Id Of 2

Yes, I tried his solution. and also I clone the other person repository in my computer to test it out that also shows the same. here is the link https://github.com/xingxingso/Laravel-5.7-From-Scratch

If you have any solution please let me know I am very thankful to you.

my complete code is online at https://github.com/hassanshahzadaheer/Laravel-5.7-From-Scratch

Jul
21
2 months ago
Activity icon

Started a new Conversation How You Study Form Laracast ?

Hi! dear all

I want to improve my knowledge and concepts. That's why I am asking this question that how you study form largest. For mine is I watch the video grab the concept and make the notes. With the video, I do what is going to teach.

Jul
18
3 months ago
Jul
17
3 months ago
Activity icon

Commented on Custom Events And Listeners

everything works fine but not receive email

Activity icon

Replied to This Action Is Unauthorized. For All User Except User Have Id Of 2

Hi! dear mstrauss

nothing gets the change I don't know where the issue occurs.

let me show the tables also

the projects table

https://prnt.sc/og3mbz

and the user's table

https://prnt.sc/og3ms8

thank you so much

Jul
16
3 months ago
Activity icon

Replied to This Action Is Unauthorized. For All User Except User Have Id Of 2

sorry I am totally new to laravel that's why I am not able to work more effectively

<?php

namespace App\Policies;

use App\User;
use App\Project;
use Illuminate\Auth\Access\HandlesAuthorization;

class ProjectPolicy
{
    use HandlesAuthorization;


    /**
     * Determine whether the user can view the project.
     *
     * @param  \App\User  $user
     * @param  \App\Project  $project
     * @return mixed
     */
    public function update(User $user, Project $project)
    {
        return $project->owner_id == $user->id;
    }


}

thank you so much I appreciate you help

Activity icon

Replied to This Action Is Unauthorized. For All User Except User Have Id Of 2

Here it is my dear

<?php

namespace App\Policies;

use App\User;
use App\Project;
use Illuminate\Auth\Access\HandlesAuthorization;

class ProjectPolicy
{
    use HandlesAuthorization;
    /**
     * Determine whether the user can view the project.
     *
     * @param  \App\User  $user
     * @param  \App\Project  $project
     * @return mixed
     */
    public function update(User $user, Project $project)
    {
        return $project->owner_id == $user->id;
    }
}

and for once I try this

return $project->owner_id == $user->id;

inside all these function

viewAny
create
delete
restore
forceDelete

thank you so much

Activity icon

Replied to This Action Is Unauthorized. For All User Except User Have Id Of 2

Hi! thank you so much but I already try this solution and it shows the same error.

but one thing please clear that where I put this line of code

Gate::define('project', function ($user, $project) {
        return $user->id == $project->user_id;
    });

and what does this variable do

$ability
Activity icon

Started a new Conversation This Action Is Unauthorized. For All User Except User Have Id Of 2

Hi!

I am stuck to understand why the code does not allow performing curd action except the superuser. I try my best to solve this problem google it but still not got the point.

my ProjectsController.php file

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Project;
use App\Mail\ProjectCreated;
class ProjectsController extends Controller
{
  public function __construct()
  {
    $this->middleware('auth');
  }
  public function index()
  {
    $projects = auth()->user()->projects;
    return view('projects.index',['projects' => $projects]);
  }

  public function create()
  {
    return view('projects.create');
  }

  public function store()
  {
    $attribute = $this->validateProject();
    $attribute['owner_id'] = auth()->id();
    Project::create($attribute);

    // \Mail::to('[email protected]')->send(
    //   new ProjectCreated($project)
    // );

    return redirect('/projects');
  }

  public function show(Project $project)
  {
    $this->authorize('update',$project);
    // if($project->owner_id !== auth()->id()){
    //   abort(403);
    // }
    return view('projects.show',['projects' => $project]);
  }

  public function edit(Project $project)
  {

    return view('projects.edit',['projects' => $project]);
  }

  public function update(Project $project)
  {
    
    $project->update($this->validateProject());
    return  redirect('/projects');
  }

  public function destroy(Project $project )
  {

     $project->delete();
     return  redirect('/projects');

  }
  public function validateProject()
  {
    return $attribute = request()->validate([
          'title' => ['required','min:3'],
          'description' => ['required','min:3']
      ]);
  }
}

AuthServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
         'App\Project' => 'App\Policies\ProjectPolicy',
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();
        Gate::before(function ($user){
            return $user->id == 2;
        });
    }
}

web.php

Activity icon

Replied to I Got A 403 Forbidden With The Other User

Hi!

still not solve try a lot ????? please help

Activity icon

Replied to I Got A 403 Forbidden With The Other User

no bro I am login with id 2

and as you ask I again log out and log in with id 1 and now it shows this error for id 2

Activity icon

Replied to I Got A 403 Forbidden With The Other User

now I got This action is unauthorized.

Activity icon

Started a new Conversation I Got A 403 Forbidden With The Other User

Hi! dear

my gate function not working it does not show me the other users projects as I am a superuser.

my code of AuthServiceProvider


class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
         'App\Project' => 'App\Policies\ProjectPolicy',
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {

        $this->registerPolicies();
        
        Gate::before(function($user){
            return $user->id == 2; //this is admin id
        });


    }
}

web.php

Route::resource('projects','ProjectsController')->middleware('can:update,project');

ProjectPolicy

  public function update(User $user, Project $project)
    {
        return $project->owner_id == $user->id;
    }

i try with

  public function boot()
    {

        $this->registerPolicies();

        Gate::before(function($user){
            //return $user->id == 2; //this is admin id
            dd("message");
        });


    }

it works fine but when I uncomment

return $user->id == 2;

it display 403

please help me how to solve this thank you so much

Jul
15
3 months ago
Activity icon

Replied to Tasks Not Found

thank you so much

Activity icon

Started a new Conversation Tasks Not Found

Hi dear all!

I am working on Laravel 5.7 from scratch series. When I add the new task and hit the button it shows me 404 error. I don't understand where I am wrong

http://localhost:8000/projects/2/tasks

ProjectTasksController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Task;
use App\Project;
class ProjectTasksController extends Controller
{

    public function store(Project $project)
    {
      Task::create([
        'project_id' => $project->id,
        'description' => request('description')
      ]);
      return back();
    }
    public function update(Task $task)
    {
      $task->update([
        'completed' => request()->has('completed')
      ]);
      return back();
    }
}

show.blade.php

@extends('layout')
@section('title','Show Project')
@section('content')
<h1 class="title">{{ $projects->title }}</h1>
<div class="content">
  {{$projects->description}}
</div>
  <a href="/projects/{{$projects->id}}/edit">Edit</a>
@if ($projects->tasks->count())
  <div class="box">
      @foreach ($projects->tasks as $task )
        <div>
          <form class="" action="/tasks/{{$task->id}}" method="post">

            {{ method_field('PATCH') }}
            {{ csrf_field() }}

              <label class="checkbox {{$task->completed ? 'is-complete' : ''}}" for="completed">
                <input class="checkbox " type="checkbox" name="completed" onchange="this.form.submit()" {{$task->completed ? 'checked' : ''}}>{{$task->description}}
              </label>
          </form>
        </div>
      @endforeach

  </div>
@endif

<form class="box" action="/projects/{{ $projects->id }}/tasks" method="post">
  {{ csrf_field() }}
  <div class="field">
    <label class="" for="add new task">Add new task</label>
    <div class="control">
      <input class="input" type="text" name="description" placeholder="Task name">
    </div>
  </div>
  <div class="field">
    <div class="control">
      <button class="button is-primary" type="submit" placeholder="">Add Task</button>
    </div>
  </div>
</form>

@endsection

web.php

Route::POST('/porjects/{porject}/tasks','[email protected]');

I don't understand where I am wrong, please help.

thank you so much

Jun
22
3 months ago
Activity icon

Replied to Integrate PHP Code With Contact Form 7 Fields

Hi! dear @braunson thank you so much for grate answer. Can you please help me how to add dropdown and display in my form because I am very stuck with this problem.

thank you so much

Jun
19
4 months ago
Activity icon

Started a new Conversation Integrate PHP Code With Contact Form 7 Fields

Hi! the question from WordPress but if anyone knows and helps me I will very thankful to you

question description in this link

https://stackoverflow.com/questions/56652051/integrate-php-code-with-contact-form-7-fields

Jun
17
4 months ago
Activity icon

Replied to Career Guide

@DEVFREY - Thanks, It was good

Jun
15
4 months ago
Activity icon

Started a new Conversation Career Guide

Hi! Dear all I just finish The PHP Practitioner series in which I learn a lot. I am a fresh graduate in computer science and want to start my career as a web developer I worked on java, PHP, HTML, CSS, Python, SQL but all the things are scattered in my mind. I don't have any job now.

I want to master the full stack web developer with good skills. I just want to know the roadmap that what steps do I need to achieve the goal. I am very impressed by the Jeffrey Way how long it will take to build skills like Jeffrey.

thank you so much

Activity icon

Started a new Conversation Warning: Require(views/{$name}.view.php):

Hi! I am facing this problem from last night I try a lot but not fix can anyone guide me how to fix this?

I make changes in pages controller file

<?php
class PagesController
{

  public function home()
  {
    $tasks = App::get('database')->selectAll('tasks');

    return view('index');

  }

  public function about()
  {

    return view('about');

  }

  public function contact()
  {
  return view('contact');

  }
}
 ?>

and got this error

Warning: require(views/{$name}.view.php): failed to open stream: No such file or directory in /opt/lampp/htdocs/re-test/index.php on line 8

Fatal error: require(): Failed opening required 'views/{$name}.view.php' (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/re-test/index.php on line 8

but I have a view function inside bootstrap.php let me show you this file

<?php


App::bind('config', require 'config.php');


App::bind('database', new QueryBuilder(
    Connection::make(App::get('config')['database'])
));

  function view($name)
  {
    return 'views/{$name}.view.php';
  }

?>

when I remove the

require from index.php 

require Router::load('routes.php')
  ->direct(Request::uri(), Request::method());


to 

Router::load('routes.php')
  ->direct(Request::uri(), Request::method());

then nothing gets display just white screen to appear on refresh

you can check the complete code on https://github.com/hassanshahzadaheer/Refactoring-to-Controller-Classes-ep-23

Jun
13
4 months ago
Activity icon

Replied to Object Not Found (The PHP Practitioner Episodes-17)

@JLRDW - yes why not

I made a change in routes.php, htaccess & request.php files

In the start, I place the root directory routes.php

<?php

$router->get('re-test','controllers/index.php');
$router->get('re-test/about','controllers/about.php');
$router->get('re-test/about/culture','controllers/about-culture.php');
$router->get('re-test/contact','controllers/contact.php');
$router->get('names','controllers/add-name.php');

.htaccess

RewriteEngine On
RewriteBase /re-test/
AddType text/css .css
AddType text/javascript .js
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteRule ^.*$ index.php [END]

Request.php

trim($_SERVER['REQUEST_URI'], '/' );
Jun
12
4 months ago
Activity icon

Replied to Object Not Found (The PHP Practitioner Episodes-17)

Hi! Dear all thank you so much for your help I have resolved my issue after a long time.

thank you

Activity icon

Started a new Conversation $_SERVER['REQUEST_URI']

Hi! dear I re-write the code and experience on the

$_SERVER['REQUEST_URI'] 

that my pages do not change it is still on the root directory which is re-test let me show the image of my result page

this is about/culture page now I understand is that must be the re-test/about/culture but the request_uri not return the right path

https://prnt.sc/o0wv8f

can you please now figure out what is the problem

thank you so much

Activity icon

Replied to Object Not Found (The PHP Practitioner Episodes-17)

Hi! dear I re-write the code and experience on the

$_SERVER['REQUEST_URI'] 

that my pages do not change it is still on the root directory which is re-test let me show the image of my result page

this is about/culture page now I understand is that must be the re-test/about/culture but the request_uri not return the right path

https://prnt.sc/o0wv8f

can you please now figure out what is the problem

thank you so much

Activity icon

Replied to Object Not Found (The PHP Practitioner Episodes-17)

@SNAPEY - Hi! my dear any solution?

Activity icon

Replied to Object Not Found (The PHP Practitioner Episodes-17)

@SNAPEY - I think no because I also try to update my routers.php class

<?php

$router->define([
    '' => 'controllers/index.php',
    'about' => 'controllers/about.php',
    'about/culture' => 'controllers/about-culture.php',
    'contact' => 'controllers/contact.php'
]);

with

  <?php

  $router->define([
      'basicPHP/' => 'controllers/index.php',
      'basicPHP/about' => 'controllers/about.php',
      'basicPHP/about/culture' => 'controllers/about-culture.php',
      'basicPHP/contact' => 'controllers/contact.php'
  ]);

Activity icon

Replied to Object Not Found (The PHP Practitioner Episodes-17)

Hi! please let me know how to set this project

Activity icon

Replied to Object Not Found (The PHP Practitioner Episodes-17)

@JLRDW - could you please give me the exact piece of code that I apply to run my project I will very thankful to you. This error stuck my life

Activity icon

Replied to Object Not Found (The PHP Practitioner Episodes-17)

@JLRDW - now show me this Fatal error: Uncaught Exception: No route defined for this URI. in /opt/lampp/htdocs/basicPHP/core/Router.php:27 Stack trace: #0 /opt/lampp/htdocs/basicPHP/index.php(6): Router->direct('/basicPHP/') #1 {main} thrown in /opt/lampp/htdocs/basicPHP/core/Router.php on line 27

Activity icon

Replied to Object Not Found (The PHP Practitioner Episodes-17)

@SNAPEY - I remove it and set as the author code

class Request { public static function uri() { return trim($_SERVER['REQUEST_URI'], '/'); } }

but nothing gets change now the index page also shows the

Jun
11
4 months ago
Activity icon

Started a new Conversation Object Not Found (The PHP Practitioner Episodes-17)

HI!

I have still a problem with the document root I applied all the solution, also change my operating system, completely remove XAMPP and install Apache & MySQL locally this method not work for me and then I reinstall xampp then try to run the app but noting gets change.

Now the home page loaded but when I visited any link it shows me this error

`` Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

Error 404 localhost Apache/2.4.37 (Unix) OpenSSL/1.0.2q PHP/7.1.26 mod_perl/2.0.8-dev Perl/v5.16.3 ``

here are those link in which I define my problem

https://laracasts.com/discuss/channels/requests/the-php-practitioner https://stackoverflow.com/questions/55365071/problem-with-redirect-to-other-pages-using-uri