Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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');

>Solution :

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');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading