Home > database >  Laravel Modal Not Returning Data
Laravel Modal Not Returning Data

Time:06-27

I am not sure why I am not getting value in Laravel controller from modal. Please help me find it out.

But, I am using the same code for other modal and controller. It's working, and it's returning values in attribute without any issue.

I am using Laravel 8 with php 8.1;

enter image description here

Below is my codes.

app\Http\Controllers\Admin\MpdController.php

public function edit(mpd $mpd)
{
    dd($mpd);
}

app\Models\admin\mpd.php

use App\Models\taxcategories;
class mpd extends Model
{
    use HasFactory;

    public $table = 'purchdata';

    protected $primaryKey = 'sno';

    protected $dates = [
        'created_at',
        'updated_at',
        'approved_at',
    ];

    protected $fillable = [
        'sno',
        'supplier',
        'stockid',
        'price',
        'discount',
        'disc_flag',
        'tax_category',
        'preferred',
        'createby',
        'modifiedby',
        'approvedby',
        'history',
    ];

    /**
     * Get the tax_category that owns the maintainpurchasingdata
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function tax_category(): BelongsTo
    {
        return $this->belongsTo(taxcategories::class, 'tax_category', 'taxrate');
    }

}

routes\web.php

Route::resource('maintainpurchase', 'MpdController');

CodePudding user response:

Route model binding will automatically determine a variable name based on the name before it

For example: Route::resource('images', 'ImageController')

Will expect Image $image in the controller.

Use php artisan route:list and look for the value between the brackets and change the

public function edit(mpd $mpd)

to

public function edit(mpd $THEVALUEBETWEENTHEBRACKETS)

Or alter the parameter name with the parameter function on the route resource definition

Route::resource('maintainpurchase', 'MpdController')->parameter('VALUEBETWEENTHEBRACKET', 'mpd');
  • Related