staticcode

staticcode

Member Since 1 Year Ago

Experience Points 3,160
Experience Level 1

1,840 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 17
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

18 Oct
9 months ago

staticcode started a new conversation Creating A Composer Package

Hi guys,

currently trying to make my own composer package, unfortunately even after following 6 tutorials I have not been able to get it working. No errors, but no working provider (did a dd() in my boot() which does nothing).

Can someone please tell me what I did wrong and -or forgot to do? a step-by-step list of what I did:

  1. I created my folder structure in the root of my (clean) Laravel 5.7 project.

packages/a/b/src/providers/

  1. In my packages/a/b/ folder I ran an "composer init". I set the name to "a/b" and the autoload psr-4 to "A\B\ : src".

  2. Added my service provider to config/app.php by adding the line "A\B\Providers\AnServiceProvider::class"

  3. I created a new class "AnServiceProvider" in the packages/a/b/src/providers/ folder with the namespace "A\B\Providers". I made a public boot() and register() function.

  4. Inside the boot() function I added a "dd('I am working')"

  5. I ran "composer dumpautoload -o" in the root directory.

  6. I ran "php artisan serve" and went to the website, which is working perfectly fine but no dd() is visible, just the normal Laravel page.

Hope someone can help me out on this matter, been trying for 2 days now without any progress no matter which tutorial I follow. Laravel wont seem to be willing to load my provider and the given files.

Best regards

28 Jun
1 year ago

staticcode left a reply on Dynamically Choose Database

oh this is exactly what I needed, thank you so much jcmargentina!

staticcode started a new conversation Dynamically Choose Database

Hi guys, I am using "one" back-end to control 22 webshops. Works fine but I kinda had to use a "hack" to dynamically choose the correct database. Up until now I am unable to find a correct "Laravel" solution for this problem.

The bad side is, that I cannot use some of the Laravel commands like "php artisan xxxx" because it will throw an error. Can someone please tell me how I can archieve the below but in a proper way?


if(isset($website[1])) {

    $companies = [
        'webshop_1',
        'webshop_2',
        'webshop_3'
    ];

    $private = [
        'webshop_4',
        'webshop_5',
        'webshop_6'
    ];

    $database = 'database_1';

    if(in_array($website[1], $companies)) {

        $database = 'database_2';

    }

    if(in_array($website[1], $private)) {

        $database = 'database_3';

    }

} else {

    $database = 'database_1';

}```
10 Jun
1 year ago

staticcode left a reply on View Not Available Eventhough It Is There

Had to use dots instead of slashes... that was all -_-

staticcode started a new conversation View Not Available Eventhough It Is There

Hi guys, my index.blade.php is extended by content.blade.php

In my content.blade.php I require three other files:

@extends('layout') @section('content')

@include('content/option1')
@include('content/option2')
@include('content/option3')

@endsection

Now Laravel tells me "View [content.option1] not found"

eventhough it does exist!

resources/views/content/option1.blade.php

When I ran it locally with php artisan serve, everything worked fine, but now it is on a server it doesnt.

Does anyone know how to fix this?

05 Jun
1 year ago

staticcode left a reply on Lumen Eloquent Delete Doing Nothing

@tykus thank you for your answer, you are totally right about the whereIn parameter, thanks for letting me know!

About the Eloquent part, any other request is working fine, just the delete requests thats are not working so I guess Eloquent is working fine seeing as I can GET and POST succesfully.

Hope you have some suggestions on how I can debug / solve this matter.

staticcode started a new conversation Lumen Eloquent Delete Doing Nothing

Hi guys,

writing an API in Lumen. Everything works fine except for "delete" routes. Somehow when ever I run a delete command, I wont get an error but my code will stop processing.

  1. I tried logging the query, returns an empty array.
  2. I tried debugging, but I get nothing back, no error nothing
  3. When I print_r / exit() before the "delete" command, I do see results
  4. When I print_r / exit() after the "delete" command nothing happens anymore

$tag is correctly filled, $idList is correctly filled.

My model is just a regular modal saying

protected $table = "collections";

and nothing more.

Hope someone can help me out on this matter.


        DB::enableQueryLog();

        $response = [];

        foreach($idList as $id) {

            $delete = Categories::where('type', '=', 'category')
                                ->where('id', '=', $id)
                                ->delete();

            print_r(DB::getQueryLog());
            print_r($delete);

            print_r($id);

//            $response[] = $delete;
//
//            $data = Redis::hgetall($tag.$id);
//
//            if (count($data) >= 1) {
//
//                $data = Redis::del($tag.$id);
//
//            }

        }

        exit();

        return response()->json($response, count($response) == 0 ? 204 : 200);

    }```
20 May
1 year ago

staticcode left a reply on Login Infinite Redirect

Long story haha. I have 1 admin to work with 20 webshops. So the public should be visible because that is the page where they chose what webshop to work with.

Only problem now is that I added Routes(); to my route, and the login / redirect everything is working, but the login page aint displayed :)

staticcode left a reply on Login Infinite Redirect

I fixed it, was a typo in my routes.php file. Only thing remaining now is that when it redirects me to

http://xxx.xxx.xxx.xxx/admin/public/login

I dont see the login screen :-O I just see my own header and footer and no content.

staticcode started a new conversation Login Infinite Redirect

Hi guys, I just added Auth to my project. it works fine as far as I can see except for the fact that when I use a new browser (in which I have not logged in yet), as expected it will redirect me to xxx.xxx.xxx.xxx/admin/public/login but the browser will give me an error :

ERR_TOO_MANY_REDIRECTS

Does anyone know where to look and or how to solve this?

Route::get('/', function () {
    return view('layout');
});

Route::middleware(['auth'])->group(function(){

// all my routes here that should be protected, and this part works!

}

Auth::routes();

Route::get('/home', '[email protected]')->name('home');
10 May
1 year ago

staticcode left a reply on Route [login] Not Defined.

yeah just found out that on the page where I set the user, it exists. When I go to any other page it does not exist... very strange :/

No clue where to look now :(

staticcode left a reply on Route [login] Not Defined.

Got a bit further... problem now is that while logging someone in I do this:

$credentials = $request->only('email', 'password');

Then on a other page when I print_r() my Auth:user() there is nothing there... how come there is nothing there?

staticcode left a reply on Route [login] Not Defined.

Didnt add Auth::routes(); because I wrote my own :)

staticcode left a reply on Route [login] Not Defined.

I have a correct route :)

staticcode started a new conversation Route [login] Not Defined.

Hi guys, i used

php artisan make:auth

after that I removed everything and wrote my own stuff. I can add a user (register), delete and edit a user. I can log in and that works perfectly fine. The only problem I am facing now is that when I want to protect a route I get this error:

InvalidArgumentException Route [login] not defined.

I did this in my web.php file:

Route::middleware(['auth'])->group(function(){

Can someone help me out on how to fix this?

05 Apr
1 year ago

staticcode left a reply on Unable To Upload BMP

We editted the server to accept files up to 10mb of size :) The BMP we are trying are either 1mb or 3mb in size.

04 Apr
1 year ago

staticcode started a new conversation Unable To Upload BMP

Hi guys,

I am trying to upload pictures, which is going fine except for BMP files. I start my check with isValid() on the uploaded image(s). This returns an error:

File not found Exception. MimeTypeGuesser.php 121

It is almost as if Laravel does not allow BMP / WBMP files te be uploaded.

In my case, I need to be able to upload the following extensions:

JPG, JPEG, PNG, BMP, WBMP, GIF

Basicly everything works fine except when uploading a BMP file. Hope someone can give me some more information on how to deal with this issue.

Best regards

if($request->file('attachment_file')->isValid()){

} else {

    return response()->json([

        'success' => false,
        'Exception' => 'Laravel returns invalid file'

    ]);

}
24 Mar
1 year ago

staticcode left a reply on Incorrect String Value

'strict' => false

in my database.php fixed the issue as well. Honestly, probably not the best way to solve an issue like this but it worked lol.

@ejdelmonico thanks for the SQL command, Ill try running it later tonight and see if I can turn the strict method back on :)

staticcode left a reply on Incorrect String Value

Ah good point @ejdelmonico , can you tell me how I can do that? all I know is that I set my table on utf8mb4_unicode_ci and that in database.php my charset is utf7mb4 and collation utf8mb4_unicode_ci :)

I just tried turning "strict" off (setting it to false). Maybe this will provide a solution as well :) Will let you know the outcome!

staticcode left a reply on Incorrect String Value

@rin4ik The CSV itself is saved in UTF-8 format :) so that should be good on that part. @ejdelmonico The row collition is set to utf8mb4_unicode_ci, so all I do manually is (in short)

insert into description values ("description here")

and that works perfectly, just not when doing it with Laravel :)

staticcode started a new conversation Incorrect String Value

Hi guys, this error is driving me nuts! I am trying to import CSV data. When I manually add it in Phpmyadmin then it works fine, but when I add it through Laravel I end up with the error below.

Tried everything but nothing solved this problem, but stuck on this for over a week now. Does anyone know a solution maybe? as said, I can add it manually in SQL no problem, just through Laravel it gives me this error so I'd say it has to do with Laravel?

My row:

article_name varchar(64) utf8mb4_unicode_ci

SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xFD)' for column 'article_name' at row 1121 (SQL: update `products` set `fk_id` = 64356, `status` = 0, `brand` = 15, `article_number` = JN001, `color` = aqua, `size` = S, `article_name` = Round-T-Medium (150g/m�), `description` = Ronde hals met elastaan en halstape geen zijnaden Dubbel gestikt op schouders hals en mouwboorde, `material` = Buitenstof 150 g/m 100% katoen, `category` = T-shirt, `washing_instructions` = Maximale wastemperatuur 40 C normale was, `color_id` = blauw, `photo_1` = art79\detail_1005.jpg, `photo_2` = art79\detail_7264.jpg, `photo_3` = art79\detail_7264_highres.jpg, `photo_4` = art79\detail_7265.jpg, `photo_5` = art79\detail_7265_highres.jpg, `photo_main` = artfarbe847\master.jpg, `weight` = 0, `price` = 3.55, `updated_at` = 2018-03-24 16:42:23 where `sku_id` = 68824)
20 Mar
1 year ago

staticcode started a new conversation Saving Pictures And Files

Hi guys, for a very large project the users must have the ability to save attachments. These attachments can be images but they can also be documents like Word, Docx, PDF et cetera.

My question now:

What is the best way to save files e.g. upload to FTP but add a prefix to the file names for example:

avatar.png becomes _avatar.png

Or would it be better to hash the filenames and store the original name with a pointer to the hashed name (2 tables) so you get ugly names like:

avatar.png becomes hjdfuhns34tgds833dfs2.png.

I hope you guys can give me some tips on what you think is the best method to do such a thing.

Keep in mind that we also need to know if someone overwrites a file, or uploads a "newer version" of the file when the name is the same.

Best regards

15 Mar
1 year ago

staticcode started a new conversation How To Upload Files Outside Of Laravel

I tried everything but cannot get a file upload to work.

I want it to upload to:

/var/www/mysite.com/uploads

Laravel is located at:

/var/www/mysite.com/admin/public/

Latest thing I tried was making a filesystem like this:

'uploads' => [
            'driver' => 'local',
            'root' => '/var/www/mysite.com/uploads'
        ]

I also tried

'uploads' => [
            'driver' => 'local',
            'root' => '../../uploads'
        ]

none of them did work.

Can anyone please tell me how I can upload files, outside of my Laravel directory to the directory I specified above?

13 Mar
1 year ago

staticcode left a reply on FirstOrCreate Not Working Properly

@samalapsy yeah did that:

echo '<pre>';
                            print_r( $items['sku_id'] );
                            echo '</pre>';

                            echo '<pre>';
                            print_r( $items['fk_id'] );
                            echo '</pre>';

                            // update or add products
                            $query = Products::updateOrCreate(['sku_id' => $items['sku_id']], [
                                'sku_id' => $items['sku_id'],
                                'fk_id' => $items['fk_id'],

strange thing is... before the update it shows me the correct values "12354" but in the database its empty. Eloquent simply does not add anything to sku_id and fk_id.

Its not a database issue, cause I can manually add them and everything is alright.

staticcode left a reply on FirstOrCreate Not Working Properly

I checked the outcome and the sku_id is the exact same as the one already in the database. There is literally zero difference between the two.

And thanks @tykus for pointing that out, didnt know :D

I tried updateOrCreate instead of firstOrCreate but when using updateOrCreate it doesnt add anything at all to the database.

staticcode started a new conversation FirstOrCreate Not Working Properly

Hi guys,

I recently made an import script by using Laravel's firstOrCreate function which, to my understanding, should update if non-existant and other create the given entry. See my code below:

$query = Products::firstOrCreate(['sku_id' => $items['sku_id']], [
                                'sku_id' => $items['sku_id'],
                                'fk_id' => $items['fk_id'],
                                'status' => $items['status'],
                                'brand' => $items['brand'],
                                'article_number' => $items['article_number'],
                                'color' => $items['color'],
                                'size' => $items['size'],
                                'article_name' => $items['article_name'],
                                'description' => preg_replace("/[^a-zA-Z0-9%\/\s]/", "", preg_replace('#\s{2,}#', ' ', (preg_replace('#\s#', ' ', $items['description'])))),
                                'material' => preg_replace("/[^a-zA-Z0-9%\/\s]/", "", $items['material']),
                                'category' => $items['category'],
                                'washing_instructions' => preg_replace("/[^a-zA-Z0-9%\/\s]/", "", $items['washing_instructions']),
                                'color_id' => $items['color_id'],
                                'photo_1' => $items['photo_1'],
                                'photo_2' => $items['photo_2'],
                                'photo_3' => $items['photo_3'],
                                'photo_4' => $items['photo_4'],
                                'photo_5' => $items['photo_5'],
                                'photo_main' => $items['photo_main'],
                                'weight' => $items['weight'],
                                'price' => ($items['price'] * 1)
                            ]);

The problem that I am having is that when I import, lets say, 2 products. And I do the import again, it just simply adds all entries again and I have 4 things in my database instead of Eloquent updating the existing values.

Can anyone explain to me what I am doing wrong?

10 Mar
1 year ago

staticcode left a reply on URL Not Found After Going Online

Oke, found out what was wrong. Since this was my first "self installed and configured server", I never activated mod_rewrite as I am used to having it activated by standard.

I had do run:

sudo a2enmod rewrite

and after that it was working!

Thanks for your replies guys!

staticcode left a reply on URL Not Found After Going Online

Yeah, in my admin/public/ folder there is a .htaccess file that comes with Laravel, that is all I know :)

Code in here is:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

php_value memory_limit 128M
php_value upload_max_filesize 200M
php_value post_max_size 200M
php_value max_input_time 9999
php_value max_execution_time 9999

staticcode left a reply on URL Not Found After Going Online

Tried that, when I go to just http://www.mysite.com/admin/ I get to see the directory index of Laravel and all the files and directories in it.

When I try admin/public/index.php/products then it does work, I get an error (which is obviously at this point) that MYSQL aint working but that is correct, havent done that yet.

So yeah, I need to make a .htaccess file I understand from this? ill try to find the examples which Laravel gives and hope I can fix it :)

Thanks very much for your answer.

staticcode started a new conversation URL Not Found After Going Online

Hi guys,

made my website locally, works fine. Then I uploaded it to my server which has this folder structure

./ (root) ./admin/ (here goes laravel)

I can see the index of my website perfectly, the url at that point is:

www.mysite.com/admin/public/

When I open a menu item and go to for example:

www.mysite.com/admin/public/products

I get a 404 not found. Locally it works fine, on the server it doesnt.

I have two questions that I hope you could answer me:

  1. How can I properly remove the "public" from the URL?
  2. How can I make my views work so I dont get a 404 not found?

I am using Ubuntu 16.04 with Apache 2 and PHP 7.2.3.

Hope someone can help me out on this matter :)

Best regards

staticcode left a reply on Blank Screen Due Unexpected ? In Route.php

I did that, I currently am using 7.2.3-1 on Ubuntu 16.04 server so should be fine right?

09 Mar
1 year ago

staticcode started a new conversation Blank Screen Due Unexpected ? In Route.php

I am getting a blank screen on my Laravel project, no error nothing. When looking in the laravel.log file I see this error:

[2018-03-09 23:48:06] laravel.ERROR: Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) at /var/www/mijnwebsite.nl/admin/vendor/symfony/routing/Route.php:53) [stacktrace] #0 /var/www/mijnwebsite.nl/admin/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile('/var/www/bedrij...') #1 [internal function]: Composer\Autoload\ClassLoader->loadClass('Symfony\\Compone...') #2 /var/www/mijnwebsite.nl/admin/vendor/laravel/framework/src/Illuminate/Routing/RouteCompiler.php(39): spl_autoload_call('Symfony\\Compone...') #3 /var/www/mijnwebsite.nl/admin/vendor/laravel/framework/src/Illuminate/Routing/Route.php(284): Illuminate\Routing\RouteCompiler->compile() #4 /var/www/mijnwebsite.nl/admin/vendor/laravel/framework/src/Illuminate/Routing/Route.php(261): Illuminate\Routing\Route->compileRoute() #5 /var/www/mijnwebsite.nl/admin/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php(197): Illuminate\Routing\Route->matches(Object(Illuminate\Http\Request), true) #6 [internal function]: Illuminate\Routing\RouteCollection->Illuminate\Routing\{closure}(Object(Illuminate\Routing\Route), 'graphql/{graphq...') #7 /var/www/mijnwebsite.nl/admin/vendor/laravel/framework/src/Illuminate/Support/Arr.php(175): call_user_func(Object(Closure), Object(Illuminate\Routing\Route), 'graphql/{graphq...') #8 /var/www/mijnwebsite.nl/admin/vendor/laravel/framework/src/Illuminate/Support/Collection.php(635): Illuminate\Support\Arr::first(Array, Object(Closure), NULL) #9 /var/www/mijnwebsite.nl/admin/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php(198): Illuminate\Support\Collection->first(Object(Closure)) #10 /var/www/mijnwebsite.nl/admin/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php(164): Illuminate\Routing\RouteCollection->matchAgainstRoutes(Object(Illuminate\Support\Collection), Object(Illuminate\Http\Request)) #11 /var/www/mijnwebsite.nl/admin/vendor/laravel/framework/src/Illuminate/Routing/Router.php(613): Illuminate\Routing\RouteCollection->match(Object(Illuminate\Http\Request)) #12 /var/www/mijnwebsite.nl/admin/vendor/laravel/framework/src/Illuminate/Routing/Router.php(602): Illuminate\Routing\Router->findRoute(Object(Illuminate\Http\Request)) #13 /var/www/mijnwebsite.nl/admin/vendor/laravel/framework/src/Illuminate/Routing/Router.php(591): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request)) #14 /var/www/mijnwebsite.nl/admin/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request)) "laravel.log" [readonly] 1503L, 283212C

Can anyone please explain to me how to fix this?

05 Mar
1 year ago

staticcode left a reply on How To Write Eloquent Like Functions With ->

ahhh thats an awesome tip, with this I can find exactly what I was looking for! thanks burlresearch!

28 Feb
1 year ago

staticcode started a new conversation How To Write Eloquent Like Functions With ->

Hi guys,

I really love the way Laravel handels a lot off stuff, especially Eloquent. But can someone explain to me how I can make stuff like this on my own? an example:

$object = new Calculator; $outcome = $object->add(15)->subtract(5)->calc();

In this case I have "one" line of code, with multiple calls to functions with the arrows ( -> ). The part that I wonder about is how could I write something like this myself so I can use multiple arrows instead of having to do it like I normally would with my classes:

$object = new Calculator; $object->add(15); $object->subtract(5); $outcome = $object->calc();

Hope someone can explain this to me on a low level so I can understand it quite well ^^

Best regards

12 Feb
1 year ago

staticcode left a reply on Upload Large Files

Looked at S3 but you need a creditcard and I dont have one so that aint an option. I read about the my hosting and they said I could add lines to my .htaccess file to manipulate the server. I tried that but still the same error, post size to large.

Does anyone has any alternatives I could try?

09 Feb
1 year ago

staticcode left a reply on Upload Large Files

Thanks for the links ill be sure to check them out. I set (more then this, but dont remember) these rules for sure:

post_max_size = 900M upload_max_filesize = 900M max_file_uploads = 20

did this with an ini_set command.

I read about the S3 yeah, but I rather handle it in my own code without using a external service like Amazone in this case. I mean... I should be able to upload files no matter the size e.g. 1mb or 1gb. Its my server, and I want to be able to upload files (they contain explicit data from companies, therefore it may not be uploaded at a 3rd party or through the user of a service like amazone).

08 Feb
1 year ago

staticcode started a new conversation Upload Large Files

Hi guys, is there a laravel way (no other packages) to upload large files? when I do:

Storage::disk('local')->put('file.xml', $request->file);

or something like that, I always end up with and error:

Illuminate \ Http \ Exceptions \ PostTooLargeException

I set the ini file to allow files over 2gb but even when uploading a file of 24mb I get this error.

Hope someone can help me out. Using Laravel 5.5

29 Jan
1 year ago

staticcode left a reply on GraphQL Not Working

Just copied the project to my laptop and there it is working fine... 1:1 the same code (pulled through GIT) so no clue what can cause this error to appear on my desktop only :(

28 Jan
1 year ago

staticcode started a new conversation GraphQL Not Working

Hi guys,

today I installed GraphQL and when I go to mysite.com/admin/public/graphiql I do see the real-time editor but it is simply not working. Whenever I do a query I get this error in return:

Cannot query field "products" on type "Query".

I copy and pasted the example code from the website (to retrieve a user) but this gave me the exact same error.

Does it have to do with the fact that my main website is located at mysite.com/ and the admin (Laravel in this case) is located at mysite.com/admin/ or is this a other problem?

I ran composer dumpautoload, composer install, composer update, php artisan clear cache/view/config et cetera but nothing solved my problem.

Hope someone can help me out on this matter :)

My Type code:

<?php
namespace App\GraphQL\Type;

use GraphQL;
use GraphQL\Type\Definition\Type;
use Folklore\GraphQL\Support\Type as GraphQLType;

class ProductType extends GraphQLType
{

    protected $attributes = [
        'name' => 'Product',
        'description' => 'A product'
    ];

    public function fields()
    {
        return [
            'id' => [
                'type' => Type::nonNull(Type::int()),
                'description' => 'The id of the product'
            ]
        ];
    }

}

My Query code:

<?php
namespace App\GraphQL\Query;

use GraphQL;
use GraphQL\Type\Definition\Type;
use Folklore\GraphQL\Support\Query;

use App\Product;

class ProductsQuery extends Query
{

    protected $attributes = [
        'name' => 'products'
    ];

    public function type()
    {
        return Type::listOf(GraphQL::type('Product'));
    }

    public function args()
    {
        return [
            'id' => ['name' => 'id', 'type' => Type::int()]
        ];
    }

    public function resolve($root, $args)
    {
        print_r('******');
        exit();
    }

}

And finally my graphql.php file:

    'schemas' => [
        'default' => [
            'query' => [
                'products' => 'App\GraphQL\Query\ProductsQuery'
            ],
            'mutation' => [

            ]
        ]
    ],

    'types' => [
        'Product' => 'App\GraphQL\Type\ProductType'
    ],
24 Jan
1 year ago

staticcode started a new conversation Laravel With GraphQL, Returning An Nested Array

I am using this package for my Laravel 5.5 installation and it is working flawless except for one small thing.

In my website we use an nested array to build our home menu. This means that we have a "main category" which can contain an "subcategory". In return, this "subcategory" can have a "subcategory" her self and thus we are able to nest menu options as deep as we want using a LEFT and RIGHT system.

What I am doing now:

I retrieve all my menu items and in PHP I build a correct array so I can display it easily in my front-end (in my case Angular 4). What PHP returns to GraphQL is this code (example code):

Array (     

[0] => stdClass Object         (             
    [id] => 1             
    [category_name] => sdgsdgsdgg             
    [clean_category_name] => sdgsdgsdgg             
    [depth] => 0             
    [post_count] => 1             
    [children] => Array                 
        (                 
        
        )          
    )      

[1] => stdClass Object         (             
    [id] => 2             
    [category_name] => fsdffsdf             
    [clean_category_name] => fsdffsdf             
    [depth] => 0             
    [post_count] => 0             
    [children] => Array                 
        (                     
            [0] => stdClass Object                         
            (                             
                [id] => 3                             
                [category_name] => xxxx                             
                [clean_category_name] => xxxx                             
                [depth] => 1                             
                [post_count] => 0                            
                [children] => Array                                 
                    (                                 
                    )                          
            )                 
        )          
    )  
)

The problem we have now is that the output of GraphiQL / GraphQL is different. It removes the "nested" fields. Example here:

{
"data": {
"categories": [
  {
    "id": 1,
    "category_name": "sdgsdgsdgg",
    "clean_category_name": "sdgsdgsdgg"
  },
  {
    "id": 2,
    "category_name": "fsdffsdf",
    "clean_category_name": "fsdffsdf"
  }
]
}
}

Meaning we are losing all nested menu options in our front-end.

We tried finding a solution in the GraphQL manual but quite frankly, we are unable to understand how to fix this, so that it will display / return multi dimensional arrays.

I hope someone can explain to us what we need to do, or give us a small example.

I will show you my GraphQL code below ;)

Best regards

CategoryQuery.php

namespace App\GraphQL\Query;

use GraphQL;
use GraphQL\Type\Definition\Type;
use Folklore\GraphQL\Support\Query;

use Modules\Kennisbank\Categories;

class CategoryQuery extends Query
{
    protected $attributes = [
        'name' => 'categories'
    ];

    public function type()
    {
        return Type::listOf(GraphQL::type('Category'));
    }

    public function args()
    {
        return [
            'id' => ['name' => 'id', 'type' => Type::string()]
        ];
    }

    // execute the query and return the data
    public function resolve($root, $args)
    {

        $categories = getCategories();

        $lastDepth = 0;
        $res = [];
        $tempParent = [];

        for($i = count($categories) - 1; $i >= 0; $i--) {

            $item = &$categories[$i];
            $item->children = [];

            if($item->depth < $lastDepth)
            {
                $item->children = $tempParent;
                $tempParent = [];
            }

            if($item->depth > 0)
                $tempParent[] = $item;

            if($item->depth == 0)
                $res[] = $item;

            $lastDepth = $item->depth;

        }

        $res = $this->reverse_tree_children_array($res);

        return $res;

    }

    private function reverse_tree_children_array($arr)
    {
        foreach ($arr as $key => $val)
        {
            if (count($val->children) > 0)
                $arr[$key]->children = $this->reverse_tree_children_array($val->children);
        }

        return array_reverse($arr);
    }
}

CategoryType.php

namespace App\GraphQL\Type;

use GraphQL\Type\Definition\Type;
use Folklore\GraphQL\Support\Type as GraphQLType;

class CategoryType extends GraphQLType
{
    protected $attributes = [
        'name' => 'Category',
        'description' => ''
    ];

protected $inputObject = false;

public function fields() {

    return [
        'id' => [
            'type' => Type::int(),
            'description' => 'The id of the FAQ'
        ],
        'category_name' => [
            'type' => Type::string(),
            'description' => ''
        ],
        'clean_category_name' => [
            'type' => Type::string(),
            'description' => ''
        ]
    ];

}

}
22 Dec
1 year ago

staticcode started a new conversation Recursive Tree

Ha guys,

learning Vue at the moment and loving it! Currently I am trying to build a recursive tree but I am really stuck and have no clue on what to do or how to do it.

I am fetching data by using Axios which works perfectly.

        axios.get('/faq/vueGetCategories')
        .then(function(response){

            this.result = response.data;

        }.bind(this))
        .catch(function(error) {

            console.log( error );

        });
        

The info that I receive back is like this:

{
    "Tree":[
        {
            "id":"1",
            "category_name":"cat1",
            "clean_category_name":"cat1",
            "depth":"0",
            "post_count":"0",
            "children":[
                {
                    "id":"4",
                    "category_name":"subcategorie 1",
                    "clean_category_name":"subcategorie-1",
                    "depth":"1",
                    "post_count":"0"
                },
                {
                    "id":"2",
                    "category_name":"subcategorie 2",
                    "clean_category_name":"subcategorie 2",
                    "depth":"1",
                    "post_count":"0"
                }
            ]
        },
        {
            "id":"3",
            "category_name":"categorie 2",
            "clean_category_name":"categorie-2",
            "depth":"0",
            "post_count":"0"
        },
        {
            "id":"5",
            "category_name":"categorie 3",
            "clean_category_name":"categorie-3",
            "depth":"0",
            "post_count":"0"
        }
    ]
}

Now, what I would like to do is build a list that works recursive like this:

<ul>
    <li class="has-children">
        NAME HERE
        <ul>
            <li>CHILD HERE</li>
        </ul>
    </li>
    <li>NAME HERE</li>
    <li>NAME HERE</li>
</ul>

The problem I am having is that, for every way I tried it, I am getting errors lol. So maybe someone could write a tiny sample code and show me the proper way on how to do something like that :)

Guess it all starts with a self-recurring template function which I tried but I didnt succeed unfortunately.

I saw the "Vue tree" example on the Vue website, but they have a header (my tree) which I dont want and I was unable to remove it from the code.

Best regards

15 Dec
1 year ago

staticcode left a reply on Relations In Model Or Controller

Very good "2 cents" lol, helpful information thanks for your reply Bobby!

staticcode started a new conversation Relations In Model Or Controller

Hi guys,

I am having a discussion here about whether to make relations directly in the model, or just write joins and stuff in the eloquent query (controller) it self.

Personally I prefer writing the joins and relations myself (old habbit) and personally I do not see the (large) benefit of doing relations in the model.

Could you guys please give me some intel on your own workflow, and the pro's and con's for doing it in the controller or model way?

Best regards

28 Nov
1 year ago

staticcode started a new conversation User Groups And Permissions For Specific Files

Hi guys, I was wondering if someone could give me some suggestions on how to to handle this.

I want this:

  1. I can make user groups and add users to it (already working)
  2. I can set read, write, update and delete permissions for groups (already working)
  3. I can set read, write, update and delete permissions for users which overwrite the group permissions (already working).

The problem I have now is that I have no clue on how to do the next part which is basicly in short:

I make a new "news item" for example.

I have 3 groups and 6 users.

Groups: A, B, C Users: 1, 2, 3, 4, 5, 6

I want the people in group A and B to be able to see the news items. Group C shouldnt be able to see it.

Users 1, 2, 3 and 6 should be able to see it, but user 4 shouldnt. User 5 is left, we havent set any permission for him for this post so his group permission will be leading.

Anyways the question, what would be the most effective way to link each "news item" that I create to each and every group and -or user.

In the end we have 300-400 categories and about 3000 users... so it will be extremely tedious to display 3k users with a checkbox lol. Thats a big no no obviously.

I hope someone can help me out on how to develop a system for something like this.

On a side note... think about the Unix permission system... we want something like that with groups and individual users.

Best regards

16 Nov
1 year ago

staticcode left a reply on Nested Set With Big Data Slow

Ahhh yeah been looking at Baum lol, will give that a try, thank you very much for your reply ^^

P.S. could you give me an indication on how much time you need to get a x-amount of results so I can compare it to my loading times?

staticcode started a new conversation Nested Set With Big Data Slow

Ha guys,

I have two questions for you.

  1. I cannot find out how to turn this into an eloquent call (if needed, otherwise Raw is fine)
  2. When I add 3000 categories it takes 16 seconds or so to load the page. How to fix this?

Some more intel on my 2nd question.

We have a large database with a large amount of categories. We are using the nested tree set model which means

Name = "A", Left = 1, Right = 4 Name = "B", Left = 2, Right = 3

A is the parent of B because the left and right of B are within the left and right of A.

When I use the following code

$catraw = DB::select( DB::raw('SELECT node.id, node.category_name, (COUNT(parent.category_name) - 1) AS depth
FROM categories AS node,
categories AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
GROUP BY node.category_name, node.id
ORDER BY node.lft') );

it takes ages for the page to load. This is because the cross-join forces MYSQL to ingnore the index on the lft and rgt (and categories_name) row.

I have no clue on how I can speed-up this process or force MYSQL to use the indexes I created.

Does anyone have a clue on how I can speed up this proces? I need to have the full tree including the depth, no way around it, I need it period. But waiting 16 seconds because the query goes through 8000 categories is insane...

Hope someone can help me out on this matter :)

25 Sep
1 year ago

staticcode left a reply on Slow Request Times (>80ms) Local

I see, will definately give that "tool" a try, thank you so much guys :) Ill post the outcome here tomorrow (not at work atm) and let you know what I found out :)

Thanks again!

24 Sep
1 year ago

staticcode started a new conversation Slow Request Times (>80ms) Local

Ha guys, I am currently developing an API for a website I am making. The problem I have now is when I look on the internet, I see large companies running Lumen with huge API's e.g. returning thousands of records and this all happens in around or less then 20ms.

When I do a simple request on my own Lumen I am developing, a simple "hello world" GET takes >80ms.

Can anyone please help me out and tell me how, and with what tools I can "monitor" or "track" the problem? I have no clue on how to or where to start searching as this is my first API that I am building.

I hope you guys can give me some tips :)

Best regards,

Angelo