Neeraj1005

Neeraj1005

Member Since 11 Months Ago

Experience Points
24,850
Total
Experience

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
124
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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 5
24,850 XP
Aug
03
2 days ago
Activity icon

Started a new Conversation Ways For Multi-Auth? Single Vs Multiple?

Hello, Laravel devs! Here I want to ask just one general question about what is the best way for a multi-auth system? If you ever have created multi auth system in your project, please share what is your opinion about this and what would be the best way?

  • single table with "type" or another column to describe auth type
  • different table for each type of authentication

Thank you in advanced :)

Jul
31
5 days ago
Activity icon

Replied to Windows, VSCode, Blade Highlight Scheme

@howdy_mcgee you can customize your vscode theme just google it about customization. and there is many extension available in vscode for theme and bracket. Spend some time and choose what you like. some refrences:

Activity icon

Replied to Get UserAgent() Details

@michaloravec but i want this without any packages. Is any other solution?

Activity icon

Started a new Conversation Get UserAgent() Details

In my Laravel project when I trying simple dd($request->userAgent()); it returns ouptut like this

"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36"

But I'm using the Chrome. How can I get single value chrome?

Jul
30
6 days ago
Activity icon

Replied to Multiple Authentication In Laravel (superadmin, Admin, Editor, User Etc...)

@michaloravec but role is internal part where admin can easily assign to role any random user. Here I'm talking about register some other type of user and then login with a single laravel login page.

Activity icon

Replied to Multiple Authentication In Laravel (superadmin, Admin, Editor, User Etc...)

@michaloravec what if I create multiple registrations using guard follow laravel default method? Is it good practice or bad?

Activity icon

Replied to Multiple Authentication In Laravel (superadmin, Admin, Editor, User Etc...)

@michaloravec Okk admin or super admin can't register. but what about other user. Suppose think a scenario like. You want to create a job board, where there are some role you want to directly register like think about as job seeking or job post. Then in this case what would you suggest?

suppose one peson is job seeker, and register. But one other person is job post then in this scenario what would I have to do?

Activity icon

Started a new Conversation Multiple Authentication In Laravel (superadmin, Admin, Editor, User Etc...)

Could anyone suggest me the working flow chart for how multiple users can register in your web or log in through one single form? Or Should I have to create a different table for Admin, editor, manager, user? How can I register these multiple users?

I know we can achieve this putting a dropdown in the register page with some status...But I don't want to use this technique..can anyone suggest me best way?

Jul
24
1 week ago
Activity icon

Replied to Image Not Showing ?

@scpworking have you run this command? php artisan storage:link and show me your blade image tag code

Jul
17
2 weeks ago
Activity icon

Replied to Eloquent Eager Loading Specific Columns

@stuartcusack

Ticket::with('subject:ticket_id,name')->get([ 'id', 'created_at']);

In this scenario, you will get subject null like this

{
	"id": 1,
	"created_at": your_data,
	"subject": null, #you will get the null eager load data
}

Let me know If I'm wrong. Because I tried this.

Activity icon

Replied to Eloquent Eager Loading

@naysoewin ok have your tried these=> select('name') OR get('name')

Activity icon

Replied to Trouble Retrieving Old Value Of Select When Editing.

@ajsmith_codes I hope this should be helpful. check this link https://talltips.novate.co.uk/laravel/using-the-old-helper

I ran into a little problem with the code. The Customer Contact only brings up the current contact in the dropdown

Activity icon

Replied to Eloquent Eager Loading

@naysoewin Basically what structure do you want to get? plz explain more... do you want to get documentation_group name only or other?

Activity icon

Replied to Eloquent Eager Loading

@naysoewin

One more Question, When i Eager Loading the products, How can i pluck 'name' only , Thanks again Like that

I think you have to just replace get() with pluck('name')

Activity icon

Replied to How Can I Refactor Code To QueryScope Laravel?

@marianomoreyra thank you for taking your time & suggestion :)

Jul
16
2 weeks ago
Activity icon

Replied to OrderBy() Does Not Work

@codinglara try to

        $categories = DB::table('categories')->orderBy('id', 'DESC')->get();
        return $categories;
    }

OR instead of return you can try this print_r($categories); and check what values it provides. If it is provides correct value then something wrong in your view file either you're using some jquery plugins for datatables.

Activity icon

Replied to How Can I Refactor Code To QueryScope Laravel?

@marianomoreyra Thant's cool answer again...I will mark this best answer. can you plz elaborate this query I'm little bit confused with that

That kind of scope is called "Dynamic Scope" according to Laravel documentation. Sure, the switch statement is static, but I left that portion of code similar to your original post, as I thought you wanted to know how to move that checking to a scope. On the other side, my first answer solves the problem for future changes. But if you are still wanting to use text instead of id as a request parameter, I guess you could do something like this:

public function scopeWithStatus($query, $status_name) 
{
return $query->whereHas('ticketStatus', function($query) use ($status_name) {
		$query->where('name', $status_name);
	});
}
Activity icon

Replied to How Can I Refactor Code To QueryScope Laravel?

@marianomoreyra Now I've modified your first answer condition clause method and its working now.

public function(Request $request){
   $status = Ticket_status::get();

        $filterBy = request('filterBy');

        $tickets = Ticket::with('users','ticketStatus','ticketType','tbl_contacts')
                    ->byAuthUser()
                    ->when($filterBy, function($query, $filterBy) {
                        // $query->where('status_id',$filterBy);
                        $query->join('ticket_statuses', 'tickets.status_id', '=', 'ticket_statuses.id')
                        ->select('tickets.*', 'ticket_statuses.name')
                        ->where('ticket_statuses.name',$filterBy);
                    })
                    ->latest()
                    ->get();
return view('ticketing.user.index',compact('tickets','status'));
}

And In blade file

 @foreach ($status as $status_item)
                                <a
                                    href="/tickets?filterBy={{ $status_item->name }}"
                                    class="btn btn-sm btn-outline-secondary mr-1">
                                    {{$status_item->name}}
                                </a>
                            @endforeach

Activity icon

Replied to How Can I Refactor Code To QueryScope Laravel?

@marianomoreyra

public function scopeWithStatus($query, $status_name) { // maybe you could use an Enum package to avoid this switch statement switch($status_name) { case 'open': return $query->where('status_id', 1); case 'pending': return $query->where('status_id', 2); case 'close': return $query->where('status_id', 3); default: return $query; } }

I think this type of technique is static, not dynamic. And in future if any changes or data is deleted this will throw an error. And conditonal clause technique is good

Activity icon

Replied to How Can I Refactor Code To QueryScope Laravel?

@marianomoreyra Really this method is awesome and we don't have to make any changes in the future. @marianomoreyra Now I want to a text in the URL like http://crm.test/tickets?filterBy=open instead of this http://crm.test/tickets?filterBy=1 how can I achieve this?

Activity icon

Replied to Can I Turn Off Video Autoplay Function On Laracasts?

@soewaiyan I think you can pause or either close the pop-up at the end. To explore the dicussion.

Jul
15
3 weeks ago
Activity icon

Started a new Conversation How Can I Refactor Code To QueryScope Laravel?

Hlw folks! I have create a filter method in my project where i filtered the data using this method

   public function index(Request $request)
    {
        $status = Ticket_status::pluck('name');

        $tickets = Ticket::with('users','ticketStatus','ticketType','tbl_contacts')
                    ->where('user_id','=',Auth::user()->id)
                    ->latest();

        if (request('Open')) {
            $tickets = $tickets->where('status_id',1)->get();
        } elseif (request('Pending')) {
            $tickets = $tickets->where('status_id',2)->get();
        } elseif (request('Close')) {
            $tickets = $tickets->where('status_id',3)->get();
        } else {
            $tickets = $tickets->get();
        }

        return view('ticketing.user.index',compact('tickets','status'));
    }

but now I want to refactor the code using queryScope method in laravel. Can anyone suggest me how to refactor this code? This above code is working fine. please help me to refactor this code. THis is my Ticket model

<?php

namespace App;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Ticket extends Model
{
    use SoftDeletes;

    //Table Name
    protected $table = 'tickets';
    //Primary key
    public $primaryKey = 'id';

    protected $fillable = [
        'ticket_number',
        'name',
        'description',
        'contact_id',
        'product_id',
        'status_id',
        'type_id',
        'priority',
        'user_id',
        'ticket_image',
        'start_date',

    ];

    protected $casts = [
        'start_date' => 'datetime',
    ];

    protected $dates = [
        'start_date',
        'deleted_at',
    ];

    protected $filepath = '/storage/';

    public function getRouteKeyName()
    {
        return 'ticket_number';
    }

    public function setStartDateAttribute($date)
    {
        $this->attributes['start_date'] = Carbon::parse($date)->format('Y-m-d H:i:s');
    }

    public function getTicketImageAttribute($value)
    {
        return asset($value ? $this->filepath.$value: 'uploads/default/products.jpg');
    }

    public function ticketType() {

        return $this->belongsTo( 'App\Ticket_type', 'type_id' );
    }

    public function ticketStatus() {

        return $this->belongsTo( 'App\Ticket_status', 'status_id' );
    }

    public function tbl_contacts() {
        return $this->belongsTo('App\Tbl_contacts', 'contact_id');
    }

    public function tbl_products() {
        return $this->belongsTo('App\Tbl_products', 'product_id');
    }

    public function users() {

        return $this->belongsTo('App\User', 'user_id');
    }

    public function getPriorityAttribute($value) {

        if ($value == 1) {

            // return "<span class='dot dot-sm dot-success'></span> Low";
            return $value;
        } elseif($value == 2) {

            // return "<small class='dot dot-sm dot-warning'></small> Medium";
            return $value;
        } else {

            // return "<span class='dot dot-sm dot-danger'></span> High";
            return $value;
        }
    }

    /**
     * Get all of the Ticket's comments.
     */
    public function comments()
    {
        return $this->morphMany('App\Comment', 'commentable');
    }

    // public function scopeFilter($query, $filters) {

    //     if ($stauts = $filters['open']) {
    //         $query->where('status_id','=',$stauts);

    //     } elseif ($stauts = $filters['pending']) {
    //         $query->where('status_id','=',$stauts);

    //     } elseif ($stauts = $filters['close']) {
    //         $query->where('status_id','=',$stauts);
    //     }

    // }

}

and this is my blade file

<div class="col-md-8">
                            <a
                                href="{{route('tickets.index')}}"
                                class="btn btn-sm btn-outline-secondary mr-1">
                                All
                            </a>
                            @foreach ($status as $status_name)
   <a
       href="/tickets?{{Str::lower($status_name)}}={{ Str::lower($status_name) }}"
       class="btn btn-sm btn-outline-secondary mr-1"> {{$status_name}}
   </a>
                            @endforeach
  
                        </div>
Jun
15
1 month ago
Activity icon

Replied to API Posts In Production Not Working

@thindery thanks for your own answer because the same case happens with me in the production level. I also didn't get why?

Jun
01
2 months ago
Activity icon

Awarded Best Reply on SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'user_id' In 'where Clause' (SQL: Select * From `outcomes` Where (`user_id` = 37 And Todos.outcome_id = Outcomes.id) And `outcomes`.`deleted_at` Is Null)

I've solve the problem using this query https://stackoverflow.com/a/62130847/8455396

  public function kanban()
    {
        $outcomes = Outcome::with(['todos' => function ($query) {
            $query->where('user_id', Auth::user()->id);
        }])->get();

        return view('taskmanagement.cruds.user.kanban',compact('outcomes'));
    }
Activity icon

Replied to SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'user_id' In 'where Clause' (SQL: Select * From `outcomes` Where (`user_id` = 37 And Todos.outcome_id = Outcomes.id) And `outcomes`.`deleted_at` Is Null)

I've solve the problem using this query https://stackoverflow.com/a/62130847/8455396

  public function kanban()
    {
        $outcomes = Outcome::with(['todos' => function ($query) {
            $query->where('user_id', Auth::user()->id);
        }])->get();

        return view('taskmanagement.cruds.user.kanban',compact('outcomes'));
    }
Activity icon

Replied to Laravel 5.8 Delete/destroy Id From Database

@paulcatalin97 I think you should have to use delete route delete

Route::delete('/listajoburi/{id}/', 'Auth\[email protected]')->name('listajoburi.destroy');

<a href="{{route('listajoburi.destroy',$row['id'])}}" class="btn btn-danger">Delete</a>
                            <form method="post" class="delete_form" action="{{route('listajoburi.destroy',$row['id'])}}">
@csrf                                
@method('delete')

                            </form>
Activity icon

Replied to SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'user_id' In 'where Clause' (SQL: Select * From `outcomes` Where (`user_id` = 37 And Todos.outcome_id = Outcomes.id) And `outcomes`.`deleted_at` Is Null)

@snapey I want to list the task with corresponding outcomes and created by the logged user plz have a look at this output https://imgur.com/Beb1OEa I've make some changes in method but I'm getting an error This is my blade file code

   public function kanban()
    {
        $outcomes = Outcome::with('todos')
        ->where(function ($query) {
            $query->select(DB::raw(1))
                  ->from('todos')
                  ->where('user_id','=',Auth::user()->id)
                  ->whereRaw('todos.outcome_id = outcomes.id');
        })
        ->get();
        return view('taskmanagement.cruds.user.kanban',compact('outcomes'));
    }
Activity icon

Started a new Conversation SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'user_id' In 'where Clause' (SQL: Select * From `outcomes` Where (`user_id` = 37 And Todos.outcome_id = Outcomes.id) And `outcomes`.`deleted_at` Is Null)

I've two tables outcomesandtodos and their corresponding Model. And in todostable I've a column name outcome_id with foreign key constrained.

In Outcomes table columns are:
id
name
created_at...

ANd in Todos table columns are
id
title
description
outcome_id
user_id

Models are

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Outcome extends Model
{
    use SoftDeletes;

    //Table Name
    protected $table = 'outcomes';
    //Primary key
    public $primaryKey = 'id';

    protected $fillable = [

    	'name'

    ];

    public function todos() {

    	return $this->hasMany('App\Todo');
    }
}

Todos

<?php

namespace App;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Todo extends Model
{
    use SoftDeletes;

    //Table Name
    protected $table = 'todos';
    //Primary key
    public $primaryKey = 'id';

    protected $fillable = [

        'todoable_id',
        'todoable_type',
        'title',
        'description',
        'admin_id',
        'user_id',
        'project_id',
        'priority',
        'outcome_id',
        'tasktype_id',
        'started_at',
        'due_time',
        'completed_at',
    ];
    public function outcome() {

        return $this->belongsTo('App\Outcome');
    }

    public function user() {

        return $this->belongsTo('App\User');
    }

    public function todoable()
    {
        return $this->morphTo();
    }


}

Now my problem is I've created a page based on outcomes table plz check this image https://imgur.com/Beb1OEa My problem is

I want to get the list of todos items with help of outcomes table which is created by Auth user. But in my case it shows all list of item. can anyone helps me out how to write the query for this. This is controller method

 public function kanban()
    {
        $outcomes = Outcome::with('todos')->get();
        // dd(Auth::user()->id);
        // $outcomes = DB::table('outcomes')
        //             ->with(DB::table('todos.*')->where('user_id','=',Auth::user()->id))
        //             ->get();
        // dd($outcomes);
        return view('taskmanagement.cruds.user.kanban',compact('outcomes'));
    }

I want to perform query like this

where('user_id','=',Auth::user()->id)

how can I do this?

Edited

 public function kanban()
    {
        $outcomes = Outcome::with('todos')
        ->where(function ($query) {
            $query->select(DB::raw(1))
                  ->from('todos')
                  ->where('user_id','=',Auth::user()->id)
                  ->whereRaw('todos.outcome_id = outcomes.id');
        })
        ->get();
        // $todos = Todo::with('outcome','user')->where([['user_id','=',Auth::user()->id],['outcome_id','=',]])->get();
        return view('taskmanagement.cruds.user.kanban',compact('outcomes'));
    }
May
25
2 months ago
Activity icon

Replied to Undefined Variable: Message (View: /home2/cricket8/public_html/crm/resources/views/auth/contacts/index.blade.php)

@michaloravec But I don't know why Is this throw an error in production mode. In my localhost is working correctly but in production it throw an error. That's why I've created a thread for this

Activity icon

Replied to Undefined Variable: Message (View: /home2/cricket8/public_html/crm/resources/views/auth/contacts/index.blade.php)

For showing error message I've used this technique from your reference Instead of this {{ $message }}

@error('first_name')
    <div class="text-danger">{{ $errors->first('first_name') }}</div>
@enderror
Activity icon

Replied to Undefined Variable: Message (View: /home2/cricket8/public_html/crm/resources/views/auth/contacts/index.blade.php)

@michaloravec okk, but what if I want to show error message also.. because this code is running properly in localhost but throw error in production

Activity icon

Started a new Conversation Undefined Variable: Message (View: /home2/cricket8/public_html/crm/resources/views/auth/contacts/index.blade.php)

In production the error $message thrown an error, why this is showing an error can anyone solve this? In localhost it runs properly

<form action="{{url('contacts')}}" method="post">
    @csrf
  <div class="form-group row">
    <label for="name" class="col-sm-3 col-form-label text-right">First Name</label>
    <div class="col-sm-9">
      <input type="text" class="form-control required @error('first_name') is-invalid @enderror" id="name" name="first_name">
      @error('first_name',)
      <div class="text-danger">{{ $message }}</div>
    @enderror
    </div>
  </div>

This is the error messge

<form action="<?php echo e(url('contacts')); ?>" method="post">
    <?php echo csrf_field(); ?>
  <div class="form-group row">
    <label for="name" class="col-sm-3 col-form-label text-right">First Name</label>
    <div class="col-sm-9">
      <input type="text" class="form-control required @error('first_name') is-invalid @enderror" id="name" name="first_name">
      @error('first_name')
      <div class="text-danger"><?php echo e($message); ?></div>
    @enderror
    </div>
May
21
2 months ago
Activity icon

Awarded Best Reply on How To Get DataTabel Header Name Under Select Dropdown Filter?

Now I've solved this problem https://stackoverflow.com/a/61927292/8455396

<script>
    $(document).ready(function() {
    $('#exampletable').DataTable( {
        "ordering": false,
        initComplete: function () {
            this.api().columns([2,3,4,8]).every( function (d) {//THis is used for specific column
                var column = this;
                var theadname = $('#exampletable th').eq([d]).text();
                var select = $('<select class="mx-1"><option value="'+d+'">'+theadname+': All</option></select>')
                    .appendTo( '#filtertable' )
                    .on( 'change', function () {
                        var val = $.fn.dataTable.util.escapeRegex(
                            $(this).val()
                        );

                        column
                            .search( val ? '^'+val+'$' : '', true, false )
                            .draw();
                    } );
                column.data().unique().sort().each( function ( d, j ) {
                    var val = $('<div/>').html(d).text();
                    select.append( '<option value="'+val+'">'+val+'</option>' )
                } );
            } );
        }
    } );
} );
</script>


Activity icon

Replied to How To Get DataTabel Header Name Under Select Dropdown Filter?

Now I've solved this problem https://stackoverflow.com/a/61927292/8455396

<script>
    $(document).ready(function() {
    $('#exampletable').DataTable( {
        "ordering": false,
        initComplete: function () {
            this.api().columns([2,3,4,8]).every( function (d) {//THis is used for specific column
                var column = this;
                var theadname = $('#exampletable th').eq([d]).text();
                var select = $('<select class="mx-1"><option value="'+d+'">'+theadname+': All</option></select>')
                    .appendTo( '#filtertable' )
                    .on( 'change', function () {
                        var val = $.fn.dataTable.util.escapeRegex(
                            $(this).val()
                        );

                        column
                            .search( val ? '^'+val+'$' : '', true, false )
                            .draw();
                    } );
                column.data().unique().sort().each( function ( d, j ) {
                    var val = $('<div/>').html(d).text();
                    select.append( '<option value="'+val+'">'+val+'</option>' )
                } );
            } );
        }
    } );
} );
</script>


May
20
2 months ago
Activity icon

Started a new Conversation How To Get DataTabel Header Name Under Select Dropdown Filter?

In my project I'm using the datatable filter https://datatables.net/examples/api/multi_filter_select.html where I've created a filter option for specific column. But the problem with this I want to show the table header name instead of All how can I get this? can anyone helps me out of this problem. Here I've put the script code plz check it and also check this image what I actually wants? https://imgur.com/U759VBL

<script>
    $(document).ready(function() {
    $('#exampletable').DataTable( {
        initComplete: function () {
            this.api().columns([3,4,5,7]).every( function () {//THis is used for specific column
                var column = this;
                var select = $('<select class="mx-1"><option value="">All</option></select>')
                    // .appendTo( $(column.footer()).empty() )
                    .appendTo( '#filltertable' )
                    .on( 'change', function () {
                        var val = $.fn.dataTable.util.escapeRegex(
                            $(this).val()
                        );

                        column
                            .search( val ? '^'+val+'$' : '', true, false )
                            .draw();
                    } );

                column.data().unique().sort().each( function ( d, j ) {
                    var val = $('<div/>').html(d).text();
                    select.append( '<option value="'+val+'">'+val+'</option>' )
                } );
            } );
        }
    } );
} );
</script>
May
15
2 months ago
Activity icon

Started a new Conversation Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException The GET Method Is Not Supported For This Route. Supported Methods: PUT, PATCH, DELETE.

I've used the partial route method. Instead of throwing an 404 page why it is throwing an error like this. How can I handle this? can anyone suggest me? THis is my route where I don't want to use show but when I tried to access show method after putting value in URL it is showing an error. plz fix to this.

       Route::resource('admin/outcomes','OutcomeController')->except([
            'show',
        ]);
May
14
2 months ago
Activity icon

Replied to DateTime::__construct(): Failed To Parse Time String (Null) At Position 0 (N): The Timezone Could Not Be Found In The Database

@michaloravec working.. Thank you.. can you please tell why my method was not working? what was the problem with this?

 public function setCompletedAtAttribute($date)
    {

        $this->attributes['completed_at'] = Carbon::parse($date)->format('Y-m-d H:i:s');
    }
Activity icon

Replied to DateTime::__construct(): Failed To Parse Time String (Null) At Position 0 (N): The Timezone Could Not Be Found In The Database

@michaloravec so what I have to do? should I remove this line?

 public function setCompletedAtAttribute($date)
    {

        $this->attributes['completed_at'] = Carbon::parse($date)->format('Y-m-d H:i:s');
    }

Edit: After removing this. THis is not also working.

Activity icon

Replied to DateTime::__construct(): Failed To Parse Time String (Null) At Position 0 (N): The Timezone Could Not Be Found In The Database

@michaloravec nothing is changed.. only timer increases. I want to put the Null if there is completed_at date. Like complete or not

Activity icon

Started a new Conversation DateTime::__construct(): Failed To Parse Time String (Null) At Position 0 (N): The Timezone Could Not Be Found In The Database

I'm trying to update the date field if it is Null or if it is not null then put the null in table. but problem is date is stored but null value is not stored. can anyone solve this problem?

#This is controller method
  public function taskcompleted(Request $request, $id)
        {
            $task = Todo::findOrFail($id);

            // if ($task->completed_at == Null) {

            //     $task->completed_at = Carbon::now();

            // }
            // else {

            //     $task->completed_at = 'Null';
            // }

            ($task->completed_at == Null) ? $task->completed_at = Carbon::now() : $task->completed_at = 'Null';

            $task->save();

            return back();
        }

#this is Model

<?php

namespace App;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Todo extends Model
{
    use SoftDeletes;

    //Table Name
    protected $table = 'todos';
    //Primary key
    public $primaryKey = 'id';

    protected $fillable = [

        'todoable_id',
        'todoable_type',
        'title',
        'description',
        'user_id',
        'priority',
        'outcome_id',
        'tasktype_id',
        'started_at',
        'due_time',
        'completed_at',
    ];

 	protected $casts = [
        'started_at' => 'datetime',
        'due_time' => 'datetime',
        'completed_at',
    ];

    protected $dates = [
        'started_at',
        'due_time',
        'completed_at',
        'created_at',
        'updated_at',
        'deleted_at',
    ];

    public function setDueTimeAttribute($date)
    {

        // $attributes['due_time'] = Carbon::createFromFormat('d-m-Y H:i:s', $date);
        $this->attributes['due_time'] = Carbon::parse($date)->format('Y-m-d H:i:s');
    }

    public function setStartedAtAttribute($date)
    {

        $this->attributes['started_at'] = Carbon::parse($date)->format('Y-m-d H:i:s');
    }

    public function setCompletedAtAttribute($date)
    {

        $this->attributes['completed_at'] = Carbon::parse($date)->format('Y-m-d H:i:s');
    }
Activity icon

Awarded Best Reply on DateTime::__construct(): Failed To Parse Time String (05-15-2020 12:00 AM) At Position 0 (0): Unexpected Character

resolved problem in my edit blade file

instead of format('m-d-Y h:i A') use this format('m/d/Y h:i A')
Activity icon

Replied to DateTime::__construct(): Failed To Parse Time String (05-15-2020 12:00 AM) At Position 0 (0): Unexpected Character

resolved problem in my edit blade file

instead of format('m-d-Y h:i A') use this format('m/d/Y h:i A')
Activity icon

Started a new Conversation DateTime::__construct(): Failed To Parse Time String (05-15-2020 12:00 AM) At Position 0 (0): Unexpected Character

I do not understand where I make a mistake. can anyone help me out of this error. This is my modal

<?php

namespace App;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Todo extends Model
{
    use SoftDeletes;

    //Table Name
    protected $table = 'todos';
    //Primary key
    public $primaryKey = 'id';

    protected $fillable = [

        'todoable_id',
        'todoable_type',
        'title',
        'description',
        'user_id',
        'priority',
        'outcome_id',
        'tasktype_id',
        'started_at',
        'due_time',
        'completed_at',
    ];

 	protected $casts = [
        'started_at' => 'datetime',
        'due_time' => 'datetime',
        'completed_at',
    ];

    protected $dates = [
        'started_at',
        'due_time',
        'completed_at',
        'created_at',
        'updated_at',
        'deleted_at',
    ];

    public function setDueTimeAttribute($date)
    {

        // $attributes['due_time'] = Carbon::createFromFormat('d-m-Y H:i:s', $date);
        $this->attributes['due_time'] = Carbon::parse($date)->format('Y-m-d H:i:s');
    }

    public function setStartedAtAttribute($date)
    {

        $this->attributes['started_at'] = Carbon::parse($date)->format('Y-m-d H:i:s');
    }

and this is my edit page start Date and due date

<div class="col">
                                    <div class="form-group">
                                        <label>Start date:</label>
                                        <div class="input-group">
                                            <div class="input-group-prepend">
                                                <span class="input-group-text">
                                                    <i class="far fa-calendar-alt"></i>
                                                </span>
                                            </div>
                                            <input
                                            type="text"
                                            class="form-control float-right"
                                            id="started_at"
                                            name="started_at"
                                            value="{{$task->started_at->format('m-d-Y h:i A')}}"
                                            />
                                        </div>
                                    </div>
                                </div>

  <div class="col">
                                    <div class="form-group">
                                        <label>Due date:</label>
                                        <div class="input-group">
                                            <div class="input-group-prepend">
                                                <span class="input-group-text">
                                                    <i class="far fa-calendar-alt"></i>
                                                </span>
                                            </div>
                                            <input
                                            type="text"
                                            class="form-control float-right"
                                            id="duetime"
                                            name="due_time"
                                            value="{{$task->due_time->format('m-d-Y h:i A')}}"
                                            />
                                        </div>
                                    </div>
                                </div>
May
11
2 months ago
Activity icon

Replied to SQLSTATE[HY000]: General Error: 1364 Field 'todoable_id' Doesn't Have A Default Value (SQL: Insert Into `todos` (`title`, `description`, `tasktype_id`, `due_time`, `outcome_id`, `user_id`, `updated_at`, `created_at`)

@tray2 in my case I have fixed 5 outcomes or may be later it will 10 but fixed. Or Todo have no limit. so my relation model is like.

  • Todo belongsToOutcomes
  • outcomes hasMany Todos
Activity icon

Replied to SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column '_token' In 'field List' (SQL: Update `todos` Set `_token` = UonSH9zn8ELeZFunPC2JKutqsSJ8tZDKDmkUHUJw, `_method` = Put, `title` = With Lead Ramesh Kumar, `description` = Mollitia Anim Volupt, `tasktyp

@tykus @ramjithap @michaloravec @drewdan Now I'm updating table using this method without creating.

        public function update(CreateTaskRequest $request, Todo $task)
        {
            $leaddata = Tbl_leads::find($request->todoable_id);

            $input = $request->validated();

            if ($request->todoable_id == '') {

                $task->update($input);
                // dd($input);

            } else {

                $input['todoable_id'] = $leaddata->ld_id;
                $input['todoable_type'] = get_class($leaddata);

                $task->update($input);
                // dd($input);
            }

            return redirect(route('tasks.index'))->with('success','succesfully updated');

        }
Activity icon

Replied to SQLSTATE[HY000]: General Error: 1364 Field 'todoable_id' Doesn't Have A Default Value (SQL: Insert Into `todos` (`title`, `description`, `tasktype_id`, `due_time`, `outcome_id`, `user_id`, `updated_at`, `created_at`)

@tray2 but their is I have a relationship like as: A Todo belongsTo one Outcomes but outcomes has many Todos. Therefore I have put the foreign key outcomes_id in Todos table.

Activity icon

Replied to SQLSTATE[HY000]: General Error: 1364 Field 'todoable_id' Doesn't Have A Default Value (SQL: Insert Into `todos` (`title`, `description`, `tasktype_id`, `due_time`, `outcome_id`, `user_id`, `updated_at`, `created_at`)

@michaloravec Okkk suppose I have created a task already and want's to update previous task then How could I do this?

$lead->todos()->create($input);

This line create new row but I want to update the existing row