Jump to content
Sign in to follow this  
mstdmstdd

In laravel 5.5 middleware modifications are not saved to db

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!

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • 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.