Laravel Voyager: Translation not working on posts and pages - php

I'm trying to add ar language to my website but I have a problem the body is not saving it saves <p> </p>
I have the request printed how I receive it when updating a post with 2 languages ar, en.
The request is as this with some dummy text
Request {#57 ▼
#json: null
#convertedFiles: array:2 [▶]
#userResolver: Closure {#1935 ▶}
#routeResolver: Closure {#1994 ▶}
+attributes: ParameterBag {#67 ▶}
+request: ParameterBag {#66 ▼
#parameters: array:17 [▼
"_token" => "LjyJ1cgN5tn7yxFbjyHRPAnRzqRKWg8ojRYM7cMP"
"title_i18n" => "{"en":"Data Services","ar":"خدمة البيانات"}"
"title" => "Data Services"
"body_i18n" => "{"ar":""}"
"body" => """
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 11.9px; margin-top: 0px; mar ▶
* Set whether or not the multilingual is supported by the BREAD input.\r\n
*/\r\n
'bread' => true,</code></pre>
"""
"excerpt_i18n" => "{"en":"as ds as d","ar":"as das s dsa"}"
"excerpt" => "as ds as d"
"slug_i18n" => "{"en":"data-services1","ar":"khdmh-albyanat"}"
"slug" => "data-services1"
"status" => "PUBLISHED"
"category_id" => "3"
"meta_description_i18n" => "{"en":"as das dsa d","ar":"asd as dasd a"}"
"meta_description" => "as das dsa d"
"meta_keywords_i18n" => "{"en":"as das","ar":"a sdas "}"
"meta_keywords" => "as das"
"seo_title_i18n" => "{"en":"Design and conduct surveys and measure relevant indicators in all areas","ar":"Design and conduct surveys and measure relevant indicators in all areas"}"
"seo_title" => "Design and conduct surveys and measure relevant indicators in all areas"
]
}
+query: ParameterBag {#65 ▶}
+server: ServerBag {#70 ▶}
+files: FileBag {#69 ▶}
+cookies: ParameterBag {#68 ▶}
+headers: HeaderBag {#71 ▶}
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: "/admin/posts"
#requestUri: "/admin/posts"
#baseUrl: ""
#basePath: null
#method: "POST"
#format: null
#session: Store {#2051 ▶}
#locale: null
#defaultLocale: "en"
-isHostValid: true
-isForwardedValid: true
basePath: ""
format: "html"
}
My voyager.php for multilanguage config is like this
'multilingual' => [
/*
* Set whether or not the multilingual is supported by the BREAD input.
*/
'bread' => true,
/*
* Set whether or not the multilingual is supported by the BREAD input.
*/
'enabled' => true,
/*
* Set whether or not the admin layout default is RTL.
*/
'rtl' => false,
/*
* Select default language
*/
'default' => 'en',
/*
* Select languages that are supported.
*/
'locales' => [
'en',
'ar',
],
],
What would be the problem?

I searched a lot, finally I tried to solve it by turning around. The solution or let's say the problem here is in this file:
posts/add-edit.blade.php
and if you remove it the bread will work perfectly with default template for posts add-edit. I think this will help a little but I don't know why this issue appear.

Related

Laravel 8 file upload validation fails with any rule

I want to validate a file upload but with literally any validation rule, I get "The (name of input) failed to upload." I've seen this issue in a few places but none of the solutions worked for me.
I'm using Laravel 8.0, php 8.0.2, and nginx/1.18.0 on ubuntu.
Controller:
public function uploadMedia (Request $request)
{
$request->validate([
'file' => 'required',
'alt' => 'required',
]);
dd('valid');
}
Blade file:
#if($errors->any())
#foreach ($errors->all() as $error)
<p class="alert error">{{ $error }}</p>
#endforeach
#endif
<form method="POST" action="/media" enctype="multipart/form-data">
#csrf
<input type="file" name="file" />
<input type="text" name="alt" placeholder="Write a short description of the image under 160 characters." />
<button type="submit">Upload</button>
</form>
If I get rid of the validation rule for 'file' it works, I get to the dd.
$request->validate([
'file' => '', // works if I do this
'alt' => 'required',
]);
I've seen other people have this issue and I've tried:
Putting another rule (max:10000, image) instead of 'required'
for the file – still get the same error.
Changing the values php.ini to post_max_size = 201M and
upload_max_filesize = 200M (this shouldn't be an issue in the
first place because the image I am trying to upload is a 136kb jpg). Verified with phpinfo();
After changing these values, reloading nginx and php-fpm
Rebooting the VM
Checking that all the double and single quotes are the correct character
Trying to upload other filetypes like png or txt, same error.
Putting 'image' as the first validation rule which worked for someone here
Removing the extra comma at the end of the rules array
Changing the name of the file input to something other than 'file'
Using a different browser (Firefox and Chrome)
Disabling all my browser extensions
Writing the validation like this instead (still get the same error):
$validator = Validator::make($request->all(), [
'file' => 'required',
'alt' => 'required'
]);
if ($validator->fails()) {
return redirect('/media')->withErrors($validator);
}
If I dd($request) before validating:
Illuminate\Http\Request {#44 ▼
#json: null
#convertedFiles: null
#userResolver: Closure($guard = null) {#255 ▶}
#routeResolver: Closure() {#264 ▶}
+attributes: Symfony\Component\HttpFoundation\ParameterBag {#46 ▶}
+request: Symfony\Component\HttpFoundation\ParameterBag {#45 ▼
#parameters: array:2 [▼
"_token" => "RrjAA2YvnSd3EYqg8vAwoWT4y6VenJzGjb5S72SU"
"alt" => "dsfghdf"
]
}
+query: Symfony\Component\HttpFoundation\InputBag {#52 ▶}
+server: Symfony\Component\HttpFoundation\ServerBag {#49 ▶}
+files: Symfony\Component\HttpFoundation\FileBag {#48 ▼
#parameters: array:1 [▼
"file" => Symfony\Component\HttpFoundation\File\UploadedFile {#33 ▼
-test: false
-originalName: "Screen Shot 2021-03-08 at 9.33.19 AM.png"
-mimeType: "application/octet-stream"
-error: 6
path: ""
filename: ""
basename: ""
pathname: ""
extension: ""
realPath: "/var/www/[my domain]/public"
aTime: 1970-01-01 00:00:00
mTime: 1970-01-01 00:00:00
cTime: 1970-01-01 00:00:00
inode: false
size: false
perms: 00
owner: false
group: false
type: false
writable: false
readable: false
executable: false
file: false
dir: false
link: false
}
]
}
+cookies: Symfony\Component\HttpFoundation\InputBag {#47 ▶}
+headers: Symfony\Component\HttpFoundation\HeaderBag {#50 ▶}
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: "/media"
#requestUri: "/media"
#baseUrl: ""
#basePath: null
#method: "POST"
#format: null
#session: Illuminate\Session\Store {#296 ▶}
#locale: null
#defaultLocale: "en"
-preferredFormat: null
-isHostValid: true
-isForwardedValid: true
-isSafeContentPreferred: null
basePath: ""
format: "html"
}
Error value of 6 means UPLOAD_ERR_NO_TMP_DIR. Ensure that your system has a properly configured upload temp directory by running php -i from command line (or phpinfo(); from a web page) and checking for the upload_tmp_dir key. On a typical Linux system this will be something like /tmp. You can set the value in php.ini if needed. Ensure permissions are correct on the listed folder, such that the web server process is allowed to write to it.
Do not attempt to use one of your publicly-accessible folders as an upload directory (e.g. saving directly to storage/app/public or similar.) Your application code should move the file into storage as described in the documentation; something like this:
public function uploadMedia(Request $request)
{
$request->validate([
'file' => ['required', 'file', 'image'],
'alt' => ['required', 'string'],
]);
$path = $request->file->store('images');
return redirect()->route('whatever')->with('success', "File saved to $path");
}

Laravel 8.12 does not show error messages

I don't understand why the error message is not displayed in form control with laravel. What is my error?
While I could get the "okey" message when I fulfill the conditions below, I could not clearly understand that the error message was not displayed because it did not meet the conditions.
"Information Is Beautiful When It Is Shared."
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Website\contact;
Route::get('/register', [contact::class, 'index'])->name('register');
Route::post('/register-submit', [contact::class, 'post'])->name('register.post');
contact.php
<?php
namespace App\Http\Controllers\Website;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class contact extends Controller
{
public function index()
{
return view('Website.contact');
}
public function post(Request $request)
{
$request->validate([
'name' => ['required', 'max:10'],
'email' => ['required'],
]);
echo "okey";
}
}
contact.blade.php
<div class="container pt-lg-5">
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form method="post" action="{{route('register.post')}}">
#csrf
<div class="form-group">
<label for="exampleInputEmail1">name</label>
<input type="text" class="form-control" name="name">
</div>
<div class="form-group">
<label for="exampleInputPassword1">E-mail</label>
<input type="email" class="form-control" name="email">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
Illuminate\Validation\Validator {#258 ▼
#translator: Illuminate\Translation\Translator {#255 ▶}
#container: Illuminate\Foundation\Application {#2 ▶}
#presenceVerifier: Illuminate\Validation\DatabasePresenceVerifier {#259 ▶}
#failedRules: array:2 [▼
"name" => array:1 [▼
"Required" => []
]
"email" => array:1 [▼
"Required" => []
]
]
#excludeAttributes: []
#messages: Illuminate\Support\MessageBag {#261 ▼
#messages: array:2 [▼
"name" => array:1 [▼
0 => "The name field is required."
]
"email" => array:1 [▼
0 => "The email field is required."
]
]
#format: ":message"
}
#data: array:3 [▶]
#initialRules: array:2 [▶]
#rules: array:2 [▼
"name" => array:2 [▼
0 => "required"
1 => "max:10"
]
"email" => array:1 [▼
0 => "required"
]
]
#currentRule: "required"
#implicitAttributes: []
#implicitAttributesFormatter: null
#distinctValues: []
#after: []
+customMessages: []
+fallbackMessages: []
+customAttributes: []
+customValues: []
+extensions: []
+replacers: []
#fileRules: array:9 [▼
0 => "Between"
1 => "Dimensions"
2 => "File"
3 => "Image"
4 => "Max"
5 => "Mimes"
6 => "Mimetypes"
7 => "Min"
8 => "Size"
]
#implicitRules: array:10 [▶]
#dependentRules: array:21 [▼
0 => "After"
1 => "AfterOrEqual"
2 => "Before"
3 => "BeforeOrEqual"
4 => "Confirmed"
5 => "Different"
6 => "ExcludeIf"
7 => "ExcludeUnless"
8 => "ExcludeWithout"
9 => "Gt"
10 => "Gte"
11 => "Lt"
12 => "Lte"
13 => "RequiredIf"
14 => "RequiredUnless"
15 => "RequiredWith"
16 => "RequiredWithAll"
17 => "RequiredWithout"
18 => "RequiredWithoutAll"
19 => "Same"
20 => "Unique"
]
#excludeRules: array:3 [▼
0 => "ExcludeIf"
1 => "ExcludeUnless"
2 => "ExcludeWithout"
]
#sizeRules: array:8 [▼
0 => "Size"
1 => "Between"
2 => "Min"
3 => "Max"
4 => "Gt"
5 => "Lt"
6 => "Gte"
7 => "Lte"
]
#numericRules: array:2 [▼
0 => "Numeric"
1 => "Integer"
]
#dotPlaceholder: "YEdPXjrZ4cLZZ3wV"
}
If you are willing for another way to solve your problem, or a quick solution you can always use Validator class directly,
First add this to your controller,
use Illuminate\Support\Facades\Validator;
Then,
public function post(Request $request)
{
$validator = Validator::make($request->all(),[
'name' => ['required', 'max:10'],
'email' => ['required'],
]);
if ($validator->fails()) {
return redirect()->back()
->withErrors($validator);
}
echo "okey";
}
In my case I solved it by removing \Illuminate\Session\Middleware\ StartSession::class from 'middleware' in Kernel.php, leaving it in the 'web' group in the same file.
go on kernal.php and find web route and removed \Illuminate\Session\Middleware\StartSession::class,
then check all validation working fine

Laravel does not see my cookies

I tried to set cookie (easy example):
Route::get('set', function () {
Cookie::queue(Cookie::forever('cart_id', 123));
});
Route::get('get', function (Illuminate\Http\Request $request) {
dump($request);
});
But I get in dump of $request:
Request {#40 ▼
...
+cookies: ParameterBag {#43 ▼
#parameters: array:3 [▼
"cart_id" => null
"XSRF-TOKEN" => null
"laravel_session" => null
]
}
+headers: HeaderBag {#46 ▼
#headers: array:9 [▼
...
"cookie" => array:1 [▼
0 => "cart_id=eyJpdiI6IldNbjJwMHdRclBmWkFkUFJ3SnJ6Z2c9PSIsInZhbHVlIjoiVnhBWGl3ODFBaGhwTCtSc0NoSmlLUT09IiwibWFjIjoiYjU2NjRmNDI4OGQ4NGZmZjNjMDhmYTEwMWJlOWQ2ZjUwYjAxNTMxYjU2OWY3Y2I0NjYxNzQzZTNhZjVkMDcxOSJ9; XSRF-TOKEN=eyJpdiI6Ino2ckNVSU5cL3VEcE5VQWRqQm1wTkV3PT0iLCJ2YWx1ZSI6IkF2b1Y0VDFkMlVqam8zeWVJQk55Mm96XC9PZFlyZUxma3FBTXNBV2VoK3AyTkp5Q2RNOHZtQnRyMFB0a3c0Mm5cL1hJdkkyY1haUHhZV0FEejdKSjMzaHc9PSIsIm1hYyI6IjFlNjVkZDE2NDJiYjA2MDQzM2JiYWYzMWY2YWRiNTk0ZDM4MjBlNmEzZmEwNTUxZWUzY2NmYmEyZDljMmYwOGIifQ%3D%3D; laravel_session=eyJpdiI6Imh1QW1iamlscnVpV3JFTThHYWdTNkE9PSIsInZhbHVlIjoiZElUMU1MZlRwa1BRZFd6T0pWMGhSanNCcmVNcjdEUGJrd2Zhc3RqbFUzVFBOamxsclBnbWhHcVk4QXFXU2VFMkVGYXBUSm4xVVFvcGZoZnVxN1VTVnc9PSIsIm1hYyI6IjkyYjA5YTI3MmE3MWE5OWRhNDBjYWZkZjQwZjk0NjI1OTY4MGNjZDM4ZDQ4YWE3YjdkMWMxNmQwZjgxMzQzZTYifQ%3D%3D"
]
]
#cacheControl: array:1 [▶]
}
}
Of course, firstly I go to /set link, then /get.
Where did I go wrong? Why all of my cookies equals to null?
By the way, last 5 hours I tried to make a function, that will contains Cookie::queue() function, but it goes wrong too. I dont know, what's wrong with my laravel cookies

How to set the timezone on sonata_type_datetime_picker

First question after using stackoverflow for years. Thanks for all the answers all over the years.
I have an issue with the sonata_type_datetime_picker.
My php.ini timezone is set to Europe/Paris.
In my sonata admin, i have a form to set date-start and date-end for a voucher.
->with('Conditions',['translation_domain' => 'SmallableAdminBundle'])
->add('startAt', 'sonata_type_datetime_picker', [
'label' => 'form.commercialvoucher.startAt',
'translation_domain' => 'SmallableAdminBundle',
'format' => 'dd/MM/yyyy HH:mm',
'attr' => [
],
])
->add('endAt', 'sonata_type_datetime_picker', [
'label' => 'form.commercialvoucher.endAt',
'translation_domain' => 'SmallableAdminBundle',
'format' => 'dd/MM/yyyy HH:mm',
'attr' => [
],
])
When i submit the form, seems the datetime are GMT time, so i lost basically one hour.
Example : When i edit my voucher, change the dates and submit, here with 10h00, i get 9:00.
CRUDController.php on line 362:
CommercialVoucher {#241 ▼
#id: 537287
#code: "TEST_time"
#name: "TEST_time"
#description: "TEST_time"
#validated: true
#startAt: DateTime {#2791 ▼
+"date": "2014-12-22 09:02:00.000000"
+"timezone_type": 1
+"timezone": "+00:00"
}
#endAt: DateTime {#2794 ▼
+"date": "2014-12-22 09:00:00.000000"
+"timezone_type": 1
+"timezone": "+00:00"
}
When i do another changes on the voucher, leaving the date unchanged, i get the right timezone.
CRUDController.php on line 362:
CommercialVoucher {#241 ▼
#id: 537287
#code: "TEST_time"
#name: "TEST_time"
#description: "TEST_time"
#validated: true
#startAt: DateTime {#1397 ▼
+"date": "2014-12-22 09:02:00.000000"
+"timezone_type": 3
+"timezone": "Europe/Paris"
}
#endAt: DateTime {#1398 ▼
+"date": "2014-12-22 09:00:00.000000"
+"timezone_type": 3
+"timezone": "Europe/Paris"
}
I tried a lot in my voucher admin, using the option format, date_format. I tried also to set timezone in the sonata config, but nothing worked so far.
I tried differents alternative solutions.
My best choice is to replace the sonata date picker by the default symfony widget.
->add('startAt', 'datetime', [
'date_widget' => 'single_text',
'time_widget' => 'single_text',
'label' => 'form.commercialvoucher.startAt',
'translation_domain' => 'SmallableAdminBundle',
'attr' => [
],
])
And i also init the date values in my entity, so that users have most often only to change day and month.
$startAt = new \DateTime('now');
$endAt = new \DateTime('now');
$startAt->setTime(0, 0, 0);
$this->setStartAt($startAt);
$endAt->setTime(23, 59, 59);
$this->setEndAt($endAt);
DateTime widget on the left
Date and Time picker

Laravel 5.2 Request to action from other controller without js

Need send request to controller Category from Wizard.
Wizard action:
$request = Request::create('/admin/category', 'POST', $this->prepare_category($row->toArray()));
Route::dispatch($request);
Category action:
public function store(Request $request, ContentPlugins $plugins)
{
dd(Request::all());
}
The request passes but Request::all() is empty []
dd on $request:
Request {#1922 ▼
#json: null
#userResolver: null
#routeResolver: null
+attributes: ParameterBag {#1859 ▼
#parameters: []
}
+request: ParameterBag {#1726 ▼
#parameters: array:11 [▼
"title" => "Фотосувениры"
"level" => "0"
"description" => null
"cost" => null
"what" => null
"type" => "catalog"
"parent" => 0
"url" => "fotosuveniry-0-0"
"sitemap" => 1
"active" => 1
"position" => 0
]
}
+query: ParameterBag {#1920 ▶}
+server: ServerBag {#1679 ▶}
+files: FileBag {#1728 ▶}
+cookies: ParameterBag {#1727 ▶}
+headers: HeaderBag {#1886 ▶}
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: null
#requestUri: null
#baseUrl: null
#basePath: null
#method: null
#format: null
#session: null
#locale: null
#defaultLocale: "en"
}
I need to get request->parameters as $_POST on Category.php (Request::all())
How to cause the action of another component and pass it parameters as when submitting the form?
That's what I need from Kohana http://kohanaframework.org/3.3/guide/kohana/requests#external-requests
This uses POST
$request = Request::factory('http://example.com/post_api')- >method(Request::POST)->post(array('foo' => 'bar', 'bar' => 'baz'));
Answer:
Input::merge($this->prepare_category($row->toArray()));
before
$request = Request::create('/admin/category', 'POST');
Route::dispatch($request);

Categories