sarmadindhar

sarmadindhar

Member Since 8 Months Ago

Experience Points 1,850
Experience Level 1

3,150 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 2
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.

03 Apr
1 month ago

sarmadindhar started a new conversation Php Artisan Command On Remote Host

Hi I have integrated laravel websocket server package for push notifications in my application . It requires the command "php artisan websockets:serve" to be executed in terminal. I executed it via putty using ssh credentials , but when I closed putty, the websocket server also closed and project stopped working properly. My question is how can I execute this command permanently on my remote server.

18 Mar
2 months ago

sarmadindhar left a reply on Route Group Prefix No Working

@TYKUS - This is an empty middleware , that I created a month ago for testing purposes

sarmadindhar left a reply on Route Group Prefix No Working

@RICHARD - Route service Provider

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        //

        parent::boot();
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $this->mapApiRoutes();

        $this->mapWebRoutes();

        //
    }

    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }
}

Web.php

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});




Route::group(['prefix' => 'admin'], function () {
    Route::get('dashboard', function ()    {
       return 'hello';
    });
});

sarmadindhar left a reply on Route Group Prefix No Working

The route group is working when I change prefix other from admin

Route::group(['prefix' => 'administrator'], function () {
    Route::get('users', function ()    {
       return 'sssssssss';
    });
});

But it is not working with 'admin' prefix

Route::group(['prefix' => 'admin'], function () {
    Route::get('users', function ()    {
        return 'working'
    });
});

sarmadindhar started a new conversation Route Group Prefix No Working

Route::group([
    'prefix' => 'admin','middleware' => ['web'],
], function() {
    Route::get('/dashboard', function() {
        return 'working';
    });
});

Whenever I remove prefix its working fine but with prefix it shows error

Class App\Admin does not exist
17 Mar
2 months ago

sarmadindhar started a new conversation Eloqouent Fetch Records B/w Time Interval

Hi! How can I fetch the records of one week from today to previous 6 days (not from start or to end day of week) or one month from today to same day of previous month (eg:18-march to 18-feb) or one year eg(18 march 2019- 18 march 2018).

10 Mar
2 months ago

sarmadindhar started a new conversation Laravel PUT Resource Not Working With Ajax Request

Hi all whenever I send a request on a put method it always return me Http exception with 419 status This only happening in PUT route , the route with post method is working fine . Although I pass csrf_token also but why its not working?

This is my route resource

Route::resource('jobs','Web\JobsController');

Ajax Request

 $.ajax({
            url: my_form.attr('action'),
            type: PUT,
            data: new FormData(my_form[0]),
            dataType: 'json',
            async: false,
            cache: false,
            processData : false,
            contentType:false,
            success: function(data){ 
        }
    })

Here is the response image https://drive.google.com/open?id=1kR9InkmNvHHc_Dl7rItAYD-GemUEP6z9

19 Feb
3 months ago

sarmadindhar left a reply on Remove Empty Array From Laravel Resource Collection

@D9705996 - I tried filter method , it removed all null values and empty arrays but now it is returning record with a numeric key in start of each record .

 $notifications=Auth::user()->notifications()->orderBy('id','DESC')->get();
        $notifications=TechnicianNotification::collection($notifications);
        $notifications=collect($notifications)->filter()->all();
return $notifications

Response

 "data": [
 "3": {
            "sender_id": 373,
            "user_id": 375,
            "sent_by": "Wayne",
            "job_id": 840,
            "service_id": 2,
            "service_name": "Furnance",
            "booking_date": "2019-02-18 13:02:22",
            "notification_type": "service_request",
            "text": "New Service Request Added",
            "date": "18 Feb 19",
            "time": "1:02 PM"
        },
"6": {
            "sender_id": 372,
            "user_id": 375,
            "sent_by": "James",
            "job_id": 840,
            "service_id": 1,
            "service_name": "AC",
            "booking_date": "2019-02-18 13:02:22",
            "notification_type": "service_request",
            "text": "New Service Request Added",
            "date": "18 Feb 19",
            "time": "1:02 PM"
        },
]
18 Feb
3 months ago

sarmadindhar started a new conversation Remove Empty Array From Laravel Resource Collection

HI all , here is my resource collection I have used merge_when() method that matches a certain condition, it works fine when the condition matches , But when the condition doesn't match the empty array is returned in collection , how to get rid of empty array when no condition is met.

My controller

   $notifications=Auth::user()->notifications()->orderBy('id','DESC')->get();
   $notifications=TechnicianNotification::collection($notifications)->resolve();
return $notification;

Resource Collection

return [

            $this->mergeWhen($this->notification_type=='service_request'&&$this->job->technician_id==0,[
                'sender_id'=>$this->sender_id,
                'sent_by'=>$this->sender['userable']['first_name'],
                'job_id'=>$this->notifiable_id,
                'service_id'=>$this->job['service']['id'],
                'service_name'=>$this->job['service']['name'],
             
                'booking_date'=>$this->job['booking_at'],
                'notification_type'=>$this->notification_type,
                'text'=>$this->text,
                'date'=>Carbon::parse($this->created_at)->format('d M y'),
                'time'=>Carbon::parse($this->created_at)->format('g:i A'),
            ]),
        ];

Response

{
    "status": 1,
    "message": "Data found",
    "data": [
        {
            "sender_id": 373,
            "sent_by": "Wayne",
            "job_id": 863,
            "service_id": 1,
            "service_name": "AC",
         
            "booking_date": "2019-02-18 15:31:08",
            "notification_type": "service_request",
            "text": "New Service Request Added",
            "date": "18 Feb 19",
            "time": "3:31 PM"
        },
        [],
        [],
        [],
        {
            "sender_id": 373,
            "sent_by": "Wayne",
            "job_id": 856,
            "service_id": 1,
            "service_name": "AC",
      
            "booking_date": "2019-02-18 13:32:16",
            "notification_type": "service_request",
            "text": "New Service Request Added",
            "date": "18 Feb 19",
            "time": "1:32 PM"
        },
        {
            "sender_id": 373,
            "sent_by": "Wayne",
            "job_id": 855,
            "service_id": 2,
            "service_name": "Furnance",
           
            "booking_date": "2019-02-18 13:25:41",
            "notification_type": "service_request",
            "text": "New Service Request Added",
            "date": "18 Feb 19",
            "time": "1:25 PM"
        },
        [],
        [],
        []
    ]
}
15 Feb
3 months ago

sarmadindhar left a reply on Accept & Save Paypal Credit Card Details From Application's Custom Interface(Not From Paypal UI)

@snapey @jlrdw @cronix

https://drive.google.com/open?id=1Tiq4bdxceOZH3Xuaq3jnoUfZ6svCgI_T

My query was just about making this functional , although I knew it it wouldnt be possible but as per clients requirement who insisted to use his own UI rather than paypal's (May be due to design consistency) , I asked the question about any other way that should be used.

The answer was so simple "You can not , rather than ........." :)

sarmadindhar left a reply on Accept & Save Paypal Credit Card Details From Application's Custom Interface(Not From Paypal UI)

@AJ-PHP - Thanks Dea Aj-PHPr.

https://drive.google.com/open?id=1Tiq4bdxceOZH3Xuaq3jnoUfZ6svCgI_T

My query was just about making this functional , although I knew it it wouldnt be possible but as per clients requirement who insisted to use his own UI rather than paypal's (May be due to design consistency) , I asked the question about any other way that should be used.

And The answer was so simple that "You cant do it rather than .........."

sarmadindhar left a reply on Accept & Save Paypal Credit Card Details From Application's Custom Interface(Not From Paypal UI)

@SNAPEY - But how the vault systems using paypal in websites work? Are they all PCI certified?

14 Feb
3 months ago

sarmadindhar started a new conversation Accept & Save Paypal Credit Card Details From Application's Custom Interface(Not From Paypal UI)

I have a rest api for an android app , that has feature of online payments , I want a customer to enter his credit card details from android app's UI , and these details are saved in db ,(Using my controller) and whenever the customer purchases any thing the charges should be deducted automatically from his saved credit card. I have searched on internet but no such tutorial found to me

sarmadindhar started a new conversation Accept & Save Paypal Credit Card Details From Application's Custom Interface(Not From Paypal UI)

I have a rest api for an android app , that has feature of online payments , I want a customer to enter his credit card details from android app's UI , and these details are saved in db , and whenever the customer purchases any thing the charges should be deducted automatically from his saved credit card. I have searched on internet but no such tutorial found to me

11 Feb
3 months ago

sarmadindhar left a reply on Where With Eager Loading

@DEVFREY - Ok its working How can I add another where condition like, jobs where status is completed and date=2019-01-26

sarmadindhar started a new conversation Where With Nested Eager Loading

Hello All The scenario is company has many technicians , technicians have many jobs Now I am getting list of jobs that are associated with the company (due to relation of technician with company and job)

$company=Company::find(1);
$jobs=$company->technicians()->with('jobs')->get()

I am getting the correct result No I want to get those jobs of company that have status eg: completed

How can I add where condition on jobs after eager loading something like

$company=Company::find(1);
$jobs=$company->technicians()->with('jobs')->where('status','completed')->get()
31 Jan
3 months ago

sarmadindhar started a new conversation Problem In Laravel Resource Transformed Data

Hi all In my system a technician has many jobs . when i fetch the records normaly all the required data is returned correctly. when I try to fetch it via resource after transforming the keys the data is returned correctly. But the problem is when I apply where condition on model each record is but each record is inside an strange numeric key

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

/**
 * @method static findOrFail($request_id)
 */
class Job extends Model
{

    public function technician(){
        return $this->belongsTo('\App\Technician');
    }

}

Technician Model

29 Jan
3 months ago

sarmadindhar left a reply on Search According To Keys Defined In Laravel Resource Collection

@MIKEMACDOWELL - Isn't it possible to filter from the transformed results returned by collection?

sarmadindhar left a reply on Search According To Keys Defined In Laravel Resource Collection

@MIKEMACDOWELL - Resource collection

<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;

class ABC extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'customer_id'=>$this->customer_id,
            'job'=>$this->id,
            'job_status'=>$this->status,
            'job_description'=>$this->description,
        ];

    }
}

Controller Code

Returns nothing

 $technician=Technician::findOrFail(1);
       $data=TechnicianJobResource::collection($technician->jobs)->where('request_status','completed');

return $data;

sarmadindhar started a new conversation Search According To Keys Defined In Laravel Resource Collection

Hi have have created a resource collection to transform my model data. When I filter data according to my specified key it return empty. But when I fitler it according to key specified in my database it works fine

How can I search data according to my specified keys .

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\Resource;

class TechnicianJobResource extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'customer_id'=>$this->customer_id,
            'job'=>$this->id,
            'job_status'=>$this->status,
            'job_description'=>$this->description,
        ];
    }



}

In Controller

This returns data b/c here I filter according to key specified in db

$technician=Technician::findOrFail(1);
$data=TechnicianJobResource::collection($technician->jobs)->where('status','=','completed');

I want to filter data according to tranformed keys but its not working

$technician=Technician::findOrFail(1);
$data=TechnicianJobResource::collection($technician->jobs)->where('job_status','=','completed');
28 Jan
3 months ago

sarmadindhar started a new conversation Difference B/w Laravel Resource Collection And Laravel Tranformer Fractal

Hi! I want to know the diff b/w laravel resource collection and laravel transformer fractals. Although both return the same output. Is their any need to use this pkg for additional features or its matter of choice? https://fractal.thephpleague.com/transformers/

This is the default laravel resource collection which can be used to transform data.

<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\Resource;


class CustomerJobs extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id'=>$this->customer_id,
            'name'=>$this->customer->first_name,
            'service_status'=>$this->status,
            'description'=>$this->description,
     
        ];
    }
}

This is also transformation of data but via laravel tranformer fractal pkg

class JobTransformer extends Fractal\TransformerAbstract
{
    public function transform(Job $job)
    {
        return [
         'id'=>$job->customer_id,
                'name'=>$job->customer->first_name,
                'service_status'=>$job->status,
                'description'=>$job->description,
    ]
    }
}
23 Jan
4 months ago

sarmadindhar started a new conversation Help In Eloquent

Hello All I have a table of Jobs with columns [id, title, description] and a table of technicians with columns [id,name,address] And a pivot table job_technician with columns [id,job_id,technician_id,job_status] The scenario is A single job is assigned to multiple technicians and when any of the technician completes the job, the job_status is changed to completed and after that no other technician will be able to process the job further. I just want to know that the specific job is completed by which technician. I want to do this via a single method or with query scope etc

suppose $job=Job::find(1); $completedBy=$job->CompletedBy() And it should return the id of the technician who has completed the job

Here are my tables

jobs(id,name,description)
technicians(id,name,address)
job_technician(id,job_id,technician_id,job_status)

Relations

class Job extends Model
{
    public function technicians(){
            return $this->belongsToMany('\App\Technician');
     }
}


class Technician extends Model
{
    public function jobs(){
            return $this->belongsToMany('\App\Job');
        }
}

sarmadindhar started a new conversation Display Date And Time According To Logged In User's Timezone

Hi all I have an application in which multiple users insert a record and a push notification is sent to other related users but these users have different timezone . My question is how can I display the record/notification creation time to every user according to his timezone. Currently I am using created_at column that displays the time only according to the timezone of user who created the record/notification.

22 Jan
4 months ago

sarmadindhar left a reply on Problem In Laravel Resource

@CIPSAS - Wow It worked Thanks alot But how it worked?

sarmadindhar left a reply on Problem In Laravel Resource

@SNAPEY - ``` public function profile(){ $users= new ProfileResource(User::find(1)); // return $users->first_name // return $users['first_name']; } Both not working

sarmadindhar left a reply on Problem In Laravel Resource

@CIPSAS - Yes ! Not working , returns nothing Same problem

sarmadindhar left a reply on Problem In Laravel Resource

@SNAPEY - But how can I access it if I have transformed data

21 Jan
4 months ago

sarmadindhar started a new conversation Problem In Laravel Resource

Hello all I have created a laravel resource that simply returns the data and it works fine But whenever I try to access any property returned via resource it returns null or gives property not available in collection error

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\Resource;

class ProfileResource extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $userData=$this->userable;
      
            return [
                'first_name' => $this->first_name,
                'last_name' => $this->last_name,
                'avatar' => $this->avatar,
                'phone' => $this->phone,
                'country' => $this->country,
                'state' => $this->state,
                'city' => $this->city,
                'address' => $this->address,
                'user_type'=>'customer',
                'password'=>'123456',
                'active'=>$this->active,
                'device_type'=>$this->device_type,
                'timezone'=>$this->timezone,
                'badge'=>$this->badge,
                'is_notification'=>$this->is_notification
            ];
    }
}

My Controller Method

function profile(){
     $user= new ProfileResource(User::find(1));
     return $user //returns user data in correct format 
     return $user->first_name//returns null
}

Data returned

{
    "data": {
        "first_name": "abcd",
        "last_name": "efgh",
        "avatar": "http://localhost/api/public/images/CustomerImages/hxNfG9oGpvdFHPx1CM60MZScJqIsNZiOjmU2RCw3.jpeg",
        "phone": 90909,
        "user_type": "customer",
        "active": 0,
        "device_type": null,
        "timezone": null,
        "badge": null,
        "is_notification": null
    }
}

sarmadindhar started a new conversation Custom Exception Handling Only For Api Routes

Hello all How can I create the custom exception handlers for api routes only Currently the exception handlers are applying on both api and web routes My api routes begin wih the api prefix eg: api/signup

18 Jan
4 months ago

sarmadindhar started a new conversation Help In Building Eloquent Relationships

Hi all. I have a system that provides services like plumber , carpenter , electrician to the customers. The system will be used by three people Customers, Companies, Technicians. The company will provide certain services like AC repair , plumber, carpenter etc The technician will select a particular company at the time of signup and will select one or more services(in which technician is specialized) that the company provides. And finally the customer will add a service request/job within specific service(Like Ac repair request) that will be accepted by any of technicians that are available for that service.And the technician will go to the address provided by customer and fix the problem.

I am much confused how to design the relations in such a way that required data can be accessed easily.

customers(name,address,phone) companies(name,registration_code,address,type) technicians(name,education,experience) services(id,name) company_service(id,company_id,service_id) technician_service(id,technician_id,service_id) jobs(id,customer_id,service_id,title,description,status) technician_job(id,job_id,technician_id)

I want to make the relations in such a way that if I can access the technicians of specific company, services provided by specific company, services provided by a technician, jobs completed by a technician, j etc etc.

14 Jan
4 months ago

sarmadindhar left a reply on Laravel Eloqouent Handling Users With Different Fields/data

@MANELGAVALDA - Ok . The child model simply extends the parent model, But the child model doesn't have its own table to store its own data separately.

class User extends Mode{
}
class Abc extends User{
}

How and where to store the data related to the Abc User?

13 Jan
4 months ago

sarmadindhar started a new conversation Laravel Eloqouent Handling Users With Different Fields/data

Hello I have different Kinds of users that have different data fields eg some users have first_name, last_name, some users have name,address some users have location , etc etc. To simplify different users have different kind of data. Only the similarity is username,email and password So my question is how to organize them in such a way that every users data can be accessed easily. Should I create one table for all the users(that seems so strange b/c there are different columns) Or is there any other way for this.

07 Jan
4 months ago

sarmadindhar started a new conversation Restricting Image For A User

Is there any way to restrict files for particular users. As currently the files are accessible via directly entering file path in url.

sarmadindhar left a reply on Default Adding Api Request Headers

@TOKOIWESLEY - Clients can access it via android or Ios I want to send a response if no header is passed. Currently It is returning html page not found instead of a specific response

sarmadindhar started a new conversation Default Adding Api Request Headers

Is there any way to add Accept=application/json header with every request in API by default. Because currently in every request I have to pass Accept header manually. Is there any method in laravel that adds this header by default/automatically with every request?

06 Jan
4 months ago

sarmadindhar left a reply on Problem In Api Request Headers

@AURAWINDSURFING - But where should I implement Try catch?

04 Jan
4 months ago

sarmadindhar started a new conversation Problem In Api Request Headers

I have built api using laravel passport and it works fine. BUt the problem happens whenever I am not passing any header like Authorization or Accept headers it provides me this error

"Type error: Argument 1 passed to Illuminate\Routing\Middleware\ThrottleRequests::addHeaders() must be an instance of Symfony\Component\HttpFoundation\Response, null given, called in C:\xampp\htdocs\bcit\vendor\laravel\framework\src\Illuminate\Routing\Middleware\ThrottleRequests.php on line 61

Is there any way to show custom response if no any header is present with request

sarmadindhar left a reply on Middle Ware No Working On Api Route

<?php

namespace App\Http\Middleware;

use Closure;

class ABCD
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
       if(1<2){
           return $next($request);
       }
  
    }
}

Kernel File

 protected $routeMiddleware = [
        'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'my_md' => \App\Http\Middleware\ABCD::class,

    ];

Route File

Route::group(['middleware' => ['auth:api','my_md']], function(){
    //customer Routes
    Route::get('customer-profile','API\[email protected]');
)}

sarmadindhar started a new conversation Middle Ware No Working On Api Route

I have built a rest api using laravel passport on which only api:auth middleware works. But whenever I make a new middleware and register it into kernel file and apply on anny route it doesnt work? Is there any other way for registering middlewares for api routes

28 Dec
4 months ago

sarmadindhar started a new conversation Error Handling In Notification MailMessage

I have created a notification in which the mail is sent to specific user But when I enter a wrong mail that doesn't exist the MailMessage returns me error code . How can I set my custom response on MailMessage when it is not sent e.g "Mail not sent"


 <?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class SignupActivate extends Notification implements ShouldQueue
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        $url = url('/api/auth/signup/activate/'.$notifiable->activation_token);

        return (new MailMessage)
                    ->subject('Confirm Your Account')
                    ->line('Thanks for signup! Please before you begin, you must confirm your account.')
                    ->action('Confirm Account', url($url))
                    ->line('Thank you for using our services!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

In my controller $mail= $user->notify(new SignupActivate($user)); I have tried this code also in if statment but it always return an error rather than bool on failure

26 Dec
4 months ago

sarmadindhar started a new conversation Help In Eloquent Relations

I have 3 types of users which can login in system, I have created separated tables for them b/c they have different fields/data from each other.I have passed user_id which is primary key in users table as foreign key in customers and company table

users(id,email,password,user_type)
customers(id,user_id,first_name,last_name,etc,etc)
company(id,user_id,company_name,address,etc)

I have two other tables services(id,name) company_service(id,company_id,service_id)

The problem is that How i should make eloquent relationships among these tables as I can get the information like user profile from related table or company's services etc.

class User extends Authenticatable
 public function customer(){
        return $this->hasOne('\App\Customer');
    }
    public function company(){
        return $this->hasOne('\App\Company');
    }
}

class company extends Model{
    return $this->hasMany('App\Service')
}
23 Dec
5 months ago

sarmadindhar started a new conversation Best Solution For Eloquent

I am creating a REST api which is basically an online service that provides services like plumber, electrician etc at your home. The system contains different roles like Customer , Company, Technician All the roles will signup first in order to use the system

The customer will ask for service and the technician from particular company will accept that request and will go to the customer's provided location in order to fix his problem after fixing the issue the technician will issue a bill to customer that he will pay to company As i have different fields for all roles except username and password so I have created different Tables for all users and passed the user_id as foreign key from users table

Tables:

  1. Users(id, username, password , user_role) : user roles are company/technician/customer
  2. Companies (id, user_id,name,lat,lng etc)
  3. Customer(id,user_id,customer_name, etc, etc)
  4. Technician(id, user_id, company_id, etc etc)

So how should I make relationships b/w these tables so I can access my desirable data easily

12 Dec
5 months ago

sarmadindhar left a reply on Issue In Data Variable

@KYLEMILLOY - There isn't any error in console the status is returned perfectly in console also

 axios.get('/check_relationship_status/1' ).
           then((resp)=>{
                this.status=resp.body.status //its pending confirmed 100%
                alert(this.status) //it alerts correct status i-e pending
           }) .catch(err => console.error(err.response));

I also tried it

 axios.get('/check_relationship_status/1' ).
           then((resp)=>{
                this.status="pending" //mannually giving value
                alert(this.status) //it alerts correct status i-e pending
           }) .catch(err => console.error(err.response));

I don't know why both are not working :(

sarmadindhar left a reply on Issue In Data Variable

@KYLEMILLOY - ``` this code

Accept Friend

export default { data() { return { status:'', } }, mounted() { axios.get('/check_relationship_status/1' ). then((resp)=>{ this.status=resp.body.status //its pending confirmed 100% //this.status="pending" //also tried it });
    },
   
}

sarmadindhar left a reply on Issue In Data Variable

@KYLEMILLOY - Sorry it was added by me in mistake but in code there isnt any such syntax error

Still its not working