Jump to content

In laravel 5.5 middleware modifications are not saved to db


mstdmstdd

Recommended Posts

Hello,

In laravel 5.5 I want to make work out for my string values when submitting the form.

 

For this I created Middleware app/Http/Middleware/WorkTextString.php :

 




<?php


namespace App\Http\Middleware;


use Closure;
use App\Http\Traits\funcsTrait;
use function PHPSTORM_META\type;


class WorkTextString
{


    use funcsTrait;
    public function handle($request, Closure $next)
    {
        $request->name = $this->workTextString($request->name); // Fields I want to modify
        $request->description = $this->workTextString($request->description);


        return $next($request);
    }


    protected function workTextString($str) // my workout for any string
    {




and in app/Http/Kernel.php I added my Middleware :

 



protected $routeMiddleware = [
    'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
    'can' => \Illuminate\Auth\Middleware\Authorize::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    'WorkTextString'=>\App\Http\Middleware\WorkTextString::class,
];


In routes/api.php : 

 



Route::group([  'prefix' => '/v1', 'namespace' => 'Api\V1', 'as' => 'api.'], function () {


    Route::resource('user_task_types', 'UserTaskTypesController', ['except' => ['create', 'edit']])->middleware('WorkTextString');


 

as I see my Middleware is triggered, but modifications are not saved to db.

Which is the right way ?

 

Thanks!

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.