samedi 30 avril 2022

yield inside section in Laravel 8

Iam trying to yield a section inside another section whitch is itself yielded in master.blade.php ,But it does not work .

master.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
   
   
   welcome to X store
    
    @yield('content')
    
</body>
</html>

shop.blade.php ( This is the view that i called in the router ) view('shop')

@extends('master')

@section('content') 


<h1> Hello ! This is Shop page </h1>

@yield('products') 


@endsection

products-grid.blade.php => this is the section that i want to yield in Shop view

@extends('shop')


@section('products')

<h3> product 1 </h3>
<h3> product 2 </h3>
<h3> product 3 </h3>
<h3> product 4 </h3>

@endsection

result

welcome to X store
Hello ! This is Shop page


via Chebli Mohamed

jeudi 28 avril 2022

How to get array values using foreach in laravel

I am new to laravel and php. I have this code in one of my controllers

$group_by_precedence = array("true", "false");

and this code in the view

@foreach  ($group_by_precedence as $value)

                    <thead>
                        <tr>
                            <th colspan="8">
                                <a class="collapse-button collapsed" data-toggle="collapse" href="#collapse_&&&&&" aria-expanded="true" aria-controls="collapse_&&&&&" onclick = "loadDealsFor(&&&&&, 'precedence');"  style="width: 100%;display: block;margin: -10px;padding: 10px;">
                                    <i class="zmdi zmdi-plus"></i> <i class="zmdi zmdi-minus"></i> exists
                                </a>
                            </th>
                        </tr>
                    </thead>
                    
                @endforeach 

I tried and not managed to know how to make the code in the view to be duplicated twice, and replace the &&&&& with the values from the $group_by_precedence array, first the true and second the false. currently the bad solution is to duplicate the code in the view, and just change the &&&&& true and false. can someone assist?



via Chebli Mohamed

outlook not receiving mails from laravel hosted website

i have implemented a mailing system in Laravel which send mails to the users when tried from localhost it is sending mails to both gmail and outlook but when i moved the code to production it only gmail accounts are receiving the mails my env file contents are :

MAIL_DRIVER="smtp" 
MAIL_HOST="smtp.gmail.com" 
MAIL_PORT="587"
MAIL_ENCRYPTION="tls" 


via Chebli Mohamed

mercredi 27 avril 2022

laravel 5.8.38 weird route issue with wildcard

I'm running a laravel 5.8.38 on nginx and have this weird route issue

the route is very simple

Route::get('/{appKey?}', 'AppSetupController@index');

that's it nothing more

the {appKey} is something created from time to time by our users with this php function

uniqid("fsapp");

so the appkey will be 18 digits characters like this, and the full url is something like this

mydomain.com/fsapp6268ad9d42fc3

we have thousands of this and everything work well except this one, this one just go straight to 404 i tried to trace the issue on the file AppSetupController on function index, but this exact appKey doesn't even land on this function, it goes straight to 404 and i don't even know how to trace this issue

if i just change even 1 character from this fsapp6268ad9d42fc3 it will go to the correct route and it just work as intended only this one i don't know why always go to 404

============SOLVED================

turns out it was 403 instead of 404, check on chrome's console the real error code was 403, not 404. but on nginx this domain was set showing 404.html on all error code

after further check, turns out there was a folder on public_html/public with that same name as the appkey



via Chebli Mohamed

How can I use laravel localization into vue components?

I'm currently working on application's translation with Laravel Localization (laravel 5.6). I succeed my text translation on blade templates but I have some view using vuejs. Into them I can't use directly laravel localization. I understand that I have to send my translations files (which are in PHP) into the vue in JS.

I found some packages like :

https://github.com/rmariuzzo/Laravel-JS-Localization ; but it doesn't support laravel 5.6 (damned)...

https://github.com/martinlindhe/laravel-vue-i18n-generator ; Laravel 5 package is no longer maintain...

This application use Laravel 5.6 and vue 2. I can't completely reorganize or upgrade Laravel or vue version.

After many research I'm still not able to do it...

Do you know how can I made translation into my vue component?

Thanks a a lot!



via Chebli Mohamed

mardi 26 avril 2022

Upload image to S3 from Tinymce using Laravel 5

I'm trying to upload an image using Tinymce to S3. Original file size is 151kb but on S3 it only goes up 24 bytes. I checked the size of the file that comes from the request to the controller and it is 151kb. Why is it only uploading 24 bytes?

This is my controller

public function upload(Request $request)
    {
        $fileName=$request->file('file')->getClientOriginalName();
        
        $folder = 'tiny/'.$fileName;
        
        $upload = Storage::put($folder, $request->file('file'));
        
        return response()->json(['location'=> url("resources/app/uploads/$fileName")]); 
        
    }

Tiny code

tinymce.init({
        selector: 'textarea',  // change this value according to your HTML
        image_class_list: [
        {title: 'img-responsive', value: 'img-responsive'},
        ],
        height: 500,
        setup: function (editor) {
            editor.on('init change', function () {
                editor.save();
            });
        },
        plugins: ['fullscreen', 'print', 'paste', 'lists advlist','autosave','image','pagebreak','table', 'toc', 'searchreplace', 'export','advcode', 'imagetools', 'autolink'],
        toolbar: 'undo redo | styleselect | forecolor | bold italic | alignleft aligncenter alignright alignjustify | outdent indent | link image | code | export | fullscreen | pagebreak',
        export_ignore_elements: [ 'iframe', 'video', 'audio' ],
        image_title: true,
        automatic_uploads: true,
        images_upload_url: base_url + 'uploadImageText',
        file_picker_types: 'image',
        file_picker_callback: function(cb, value, meta) {
            var input = document.createElement('input');
            input.setAttribute('type', 'file');
            input.setAttribute('accept', 'image/*');
            input.onchange = function() {
                var file = this.files[0];

                var reader = new FileReader();
                reader.readAsDataURL(file);
                reader.onload = function () {
                    var id = 'blobid' + (new Date()).getTime();
                    var blobCache =  tinymce.activeEditor.editorUpload.blobCache;
                    var base64 = reader.result.split(',')[1];
                    var blobInfo = blobCache.create(id, file, base64);
                    blobCache.add(blobInfo);
                    cb(blobInfo.blobUri(), { title: file.name });
                };
            };
            input.click();
        },
        content_css: "writer",
        content_style: "body { margin: 0rem auto; max-width: 900px; }" + " p{word-break: break-word !important}" + " .mce-pagebreak { display: block !important; page-break-after: always !important;}",
        pagebreak_split_block: true
    });


via Chebli Mohamed

Same route different controllers

im trying to use same route but different controllers, but not getting a clean and good solution for it, for example my intention is:

Domain.com/category-slug

Domain.com/article-slug

But each one have different controller, using the same structure routes doesnt go to the intended controller, above leave my web.php

Route::get('/', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/{category}', [App\Http\Controllers\QuestionController::class, 'index'])->name('category.list');

Route::get('/{slug}', [App\Http\Controllers\QuestionController::class, 'show'])->name('questions.show');

Does someone got the same situation and how it handle it?



via Chebli Mohamed