2017-12-01 1 views
-1

laravel 5.5에서 양식을 제출할 때 문자열 값을 처리하고 싶습니다. 이를 위해laravel 5.5에서 미들웨어 수정 사항이 데이터베이스에 저장되지 않았습니다

은 내가 만든 미들웨어 응용 프로그램/HTTP/미들웨어/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 
    { // some string routing, like trimming more 2 spaces inside of string 
    ... 

및 응용 프로그램에

/내 미들웨어 추가 HTTP/Kernel.php : 루트에서

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, 
]; 

를/api.php :

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

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

내 미들웨어가 트리거 된 것처럼 보이지만 수정 사항이 db에 저장되지 않습니다. 올바른 방법은 무엇입니까?

감사합니다.

+0

제목을 편집하십시오. 요청하신 내용이 명확하지 않습니다. 또한'workTextString()'정의를 보여준다. – Camilo

답변

1

요청한 데이터를 업데이트하고 싶습니다.

$request->merge([ 
    'name' => $this->workTextString($request->name), 
    'description' => $this->workTextString($request->description), 
]); 

또는

$request['name'] = $this->workTextString($request->name); 
$request['description'] = $this->workTextString($request->description); 

Request

는 당신이 실제로 실제로 입력으로 사용되는 내용에 어떤 변수를 설정되지 않도록 __set 방법이없는 : 당신은 새로운 데이터에 병합 시도 할 수 속성을 설정할 때 소스, $request->name = ...;

코드의 어떤 부분이 DB와 ​​관련이 있는지 확실하지 않지만.

관련 문제