Skip to content
Advertisement

Laravel Modal Not Returning Data

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.

appHttpControllersAdminMpdController.php

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

appModelsadminmpd.php

use AppModelstaxcategories;
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 IlluminateDatabaseEloquentRelationsBelongsTo
     */
    public function tax_category(): BelongsTo
    {
        return $this->belongsTo(taxcategories::class, 'tax_category', 'taxrate');
    }

}

routesweb.php

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

Advertisement

Answer

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');
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement