S
S
Sergey Zavialov2019-04-04 08:22:50
Laravel
Sergey Zavialov, 2019-04-04 08:22:50

Laravel 5.8 why is the text encrypted when added to the site?

there is a template for adding text to the site

@extends('default.layouts.layout')

@section('content')

<div class="col-md-9">

  <div class="">
    <h2>Добавление нового материала</h2>
    </div>
  
  @if (count($errors) > 0)
      <div class="alert alert-danger">
          <ul>
              @foreach ($errors->all() as $error)
                  <li>{{ $error }}</li>
              @endforeach
          </ul>
      </div>
  @endif

  @if (session('message'))
      <div class="alert alert-success">
          {{ session('message') }}
      </div>
  @endif
  
  <form method="post" action="{{ route('admin_add_post_p') }}">
  <input type="hidden" name="_token" value="{{ csrf_token() }}">
    <div class="form-group">
      <label for="name">Заголовок</label>
      <input type="text" class="form-control" id="name" name="name" value="{{ old('name') }}" placeholder="Заголовок">
    </div>
    <div class="form-group">
      <label for="img">Изображение</label>
      <input type="text" class="form-control" id="img" value="{{ old('img') }}" name="img" placeholder="img">
    </div>
    <div class="form-group">
      <label for="text">Text</label>
      <textarea class="form-control" id="text" name="text" rows="3">{{ old('text') }}</textarea>
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
  </form>
</div>	
@endsection

There is a controller that processes the request
<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\User;
use Auth;

use Gate;

class AdminPostController extends Controller
{
    //show Form
    public function show() {
    return view('default.add_post',['title' => 'Новый материал']);
  }
  
  //new post
    public function create(Request $request) {
    	
    	if(Gate::denies('add-article')) {
      return redirect()->back()->with(['message'=>'У Вас нет прав']);
    }
    	
    	
    	$this->validate($request,[
    		'name'=>'required'
    	]);
    	
    	$user = Auth::user();
    	$data = $request->all();
    	
    	$res = $user->articles()->create([
            'name' => $data['name'],
            'img' => $data['img'],
            'text' => $data['text']
        ]);
        
       
    return redirect()->back()->with('message','Материал добавлен');
       
  }
}

It's kind of surreal. The name of the article, the name field is added correctly, the img field i.e. the picture does not see at all, the text field text itself is displayed by some kind of abracadabra, in encrypted form.
Type
"\u043f\u0440\u0438\u0432\u0435\u0442"
figures are displayed correctly, only taken in quotation marks
"00000000"
. recoded back
What could be the problem here? Here, as I understand it, again tricks with the famous CSRF protection. Or something different.
5ca5952d39c85217155302.jpeg5ca594fae1396695480439.jpeg

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Kuznetsov, 2019-04-04
@dima9595

It's not a cipher, it's an encoding. This is how Russian characters are written to the database.

R
Roman, 2019-04-04
@procode

"\u043f\u0440\u0438\u0432\u0435\u0442"

This is what unicode looks like))
Deal with encodings.

G
Gregory, 2019-04-04
@difiso

It's not encryption, it's just escaped unicode. When saving arrays to the database, Laravel uses the usual json_encode() without additional parameters (JSON_UNESCAPED_UNICODE, in this case), which leads to this type of string. Don't worry, no data will be lost.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question