Home  >  Q&A  >  body text

Laravel Modal does not return data

I don't know why I'm not getting the value from the modal in my Laravel controller. Please check it for me.

However, I use the same code for other modes and controllers. It's working and returning the value from the property without any issues.

I'm using Laravel 8 and php 8.1;

Below is my code.

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

}

routing\web.php

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

P粉174151913P粉174151913178 days ago264

reply all(1)I'll reply

  • P粉920199761

    P粉9201997612024-03-30 09:13:42

    Route model binding will automatically determine the variable name based on the name in front of the variable name

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

    Expect Image $image to exist in the controller.

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

    public function edit(mpd $mpd)

    to

    public function edit(mpd $THEVALUEBETWEENTHEBRACKETS)

    Or use the parameter function on the routing resource definition to modify the parameter name

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

    reply
    0
  • Cancelreply