Tray2

Tray2

Oracle Developer (PL/SQL, Forms & Apex) at Scania CV AB

Member Since 6 Years Ago

Solna

Experience Points
349,070
Total
Experience

0 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
1477
Lessons
Completed
Best Reply Awards
301
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

  • community-pillar Created with Sketch.

    Community Pillar

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

Level 50
349,070 XP
Dec
03
15 hours ago
Activity icon

Replied to Query Builder: How To Return 2 Results From One Query

so something like this then?

SELECT * FROM table1
UNION ALL
SELECT * FROM table2
Activity icon

Replied to Store Images One/two Levels Higher, Outside Of The Project

Wohoo! I stole one from the all mighty @sinnbeck and that my friends is a big achievment :)

Activity icon

Awarded Best Reply on Store Images One/two Levels Higher, Outside Of The Project

I agree with @sinnbeck that you should use a symlink to acheive that.

Other than that something like

$path = base_path() . '/../../';

migth work.

Activity icon

Replied to How To Get Video Duration While Upload Video File

While you upload is a bit tricky since it requires certain software installed on the users computer.

However you can use ffmpeg to get loads of information after the upload is done.

https://github.com/PHP-FFMpeg/PHP-FFMpeg

You can of course do it from the command line as well and not use the library.

Here is a little script that I made a while back that takes all the media files in a directory and recodes them at a lower resolution.

<?php
  $dir = $argv[1];
  $list = $argv[2];
function getDirContents($dir, &$results = array()){
    $files = scandir($dir);

    foreach($files as $key => $value){
        $path = realpath($dir.DIRECTORY_SEPARATOR.$value);
        if(!is_dir($path)) {
            $results[] = $path;
        } else if($value != "." && $value != "..") {
            getDirContents($path, $results);
            $results[] = $path;
        }
    }

    return $results;
}

function getMediaFiles($contentList)
{
	$allowedTypes = ['mpg', 'mp4', 'mkv', 'flv', 'mov', 'mpeg', 'avi', 'wmv'];
	$mediaFiles = [];

	foreach($contentList as $row) {
		if(is_file($row)) {
			$extension = pathinfo($row, PATHINFO_EXTENSION);
			if(in_array($extension, $allowedTypes)) {
				$mediaFiles[] = $row;
			}
		}
	}

	return $mediaFiles;
}

function getMediaFilesToResize($mediaList)
{
	$mediaToResize = [];
	foreach($mediaList as $row) {
		$command = 'ffmpeg -i ' . str_replace(' ', '\ ', $row) . ' 2>&1 | grep Video: | grep -Po \'\d{3,5}x\d{3,5}\' | cut -d\'x\' -f2';
		$height = (int)exec($command);
        if ($height > 720) {
            $mediaToResize[] = $row;
        }
	}
	return $mediaToResize;
}

function startResize($mediaToResize)
{
	$num = 1;
	$total = count($mediaToResize);
	$originalSize = 0;
	$newSize = 0;
	
	foreach($mediaToResize as $row) {
		$extension = pathinfo($row, PATHINFO_EXTENSION);
		$filename = trim(str_replace(' ', '_', basename($row, $extension)), '.');
		echo "Processing file $num of $total\n";
	    echo "Starting conversion of $filename\n";
		$originalSize += filesize($row);
		$command = 'ffmpeg -loglevel quiet -stats -i ' . str_replace(' ', '\ ', $row) . ' -vf scale=1280:720 ' . str_replace(' ', '\ ',pathinfo($row, PATHINFO_DIRNAME)) .'/' . $filename . '-720p.' . $extension;
		exec($command);
		unlink($row);
		$newSize += filesize(pathinfo($row, PATHINFO_DIRNAME).'/' . $filename . '-720p.' . $extension);
		$num++;
		echo "Done processing $row!\n";
	}

	return ['old_size' => $originalSize, 'new_size' => $newSize];
}

function getEarnedSpace($result)
{
	return round(($result['old_size'] - $result['new_size']) / 1024 / 1024 / 1024, 3);
}

function main($dir, $list = null)
{
	$files = getDirContents($dir);
	$mediaFiles = getMediaFiles($files);
	$mediaToResize = getMediaFilesToResize($mediaFiles);
    if ($list == null) {
        $result = startResize($mediaToResize);
        $freedSpace = getEarnedSpace($result);
        echo "Conversion Finshed\n";
        echo "You have freed up $freedSpace Gb of space on your harddrive\n";
    } else {
		print_r($mediaToResize);
	}
}

main($dir, $list);
Activity icon

Replied to Why This Join Return 11000 Results

Usually it's good to add another join condition to the query but that depends on how the tables look and what the expected result is.

That is why I asked you to share the generated sql.

I'm not a big fan of the "new" join syntax, I prefer doing then the old fashioned way in my SQL.

This part looks like an unconditional join to me

->join('category_product', function($join) {
		$join->on('category_product.product_id', '=', 'manufacturer_product.product_id')
			->where('category_product.category_id', '=', $this->id);

You probably need to add some conditions to it

->join('category_product', function($join) {
		$join->on('category_product.product_id', '=', 'manufacturer_product.product_id')
			->where('category_product.category_id', '=', $this->id)->on(<condition here>);
Activity icon

Replied to Store Images One/two Levels Higher, Outside Of The Project

Mark the answer that helped you as best :)

Activity icon

Replied to Why This Join Return 11000 Results

You have something called a cartesian product there.

It means that one of your joins gets joined in 1 to all instead of 1 to 1.

Look att the genereated sql from the code below.

dd( Manufacturer::select('manufacturers.*')
	->withTranslations( LanguageHelper::getLangId() )
	->with('image')
	->join('manufacturer_product', 'manufacturers.id', '=', 'manufacturer_product.manufacturer_id')
	->join('category_product', function($join) {
		$join->on('category_product.product_id', '=', 'manufacturer_product.product_id')
			->where('category_product.category_id', '=', $this->id);
	})->toSql());
Activity icon

Replied to Dynamic Sections With Tailwind UI In A Laravel App. Some Ideas?

Thank m8 :) There will be cake today ;)

Activity icon

Replied to Validation Error: The Logo Must Be An Image.

Since you pull the record from the database you only need to update it if a file has been provided

if ($request->hasFile('logo')) {
    //Do the stuff here to update the image
}

If it has no image provided it will use the one you alredy got.

Activity icon

Replied to Query Builder: How To Return 2 Results From One Query

Distinct should be avoided if possible.

However what do you mean by two query responses?

Are the tables related like author and book or is it more like authors and artists and you want to list both the artists and the authors with one query?

Activity icon

Awarded Best Reply on Dynamic Sections With Tailwind UI In A Laravel App. Some Ideas?

A components table perhaps

  • id
  • name
  • tag

Where the tag is the <x-component />

You could also have a componen_parameters table where the parameters that can be passed to the component

  • id
  • component_id
  • parameter
  • default_value
Activity icon

Replied to Validation Error: The Logo Must Be An Image.

Yes

'logo' => 'image|max:512|nullable',

But I prefer to have this order instead

'logo' => 'nullable|image|max:512',

But that is just my preference.

Activity icon

Replied to Validation Error: The Logo Must Be An Image.

Stealing my thunder again I see ;p

Activity icon

Replied to Which Docker Source Is Preferable For Installing Laravel Under Docker ?

I'm just starting to learn about docker for laravel but I really recommend this course on it.

https://gumroad.com/l/cwYKw

It covers a lot on developing and on deploying to production

Activity icon

Replied to Validation Error: The Logo Must Be An Image.

You can use nullable in your validation rule.

Make sure to only update the value if a file is present.

https://laravel.com/docs/8.x/validation#rule-nullable

Activity icon

Replied to Dynamic Sections With Tailwind UI In A Laravel App. Some Ideas?

A components table perhaps

  • id
  • name
  • tag

Where the tag is the <x-component />

You could also have a componen_parameters table where the parameters that can be passed to the component

  • id
  • component_id
  • parameter
  • default_value
Activity icon

Replied to Store Images One/two Levels Higher, Outside Of The Project

I agree with @sinnbeck that you should use a symlink to acheive that.

Other than that something like

$path = base_path() . '/../../';

migth work.

Activity icon

Replied to Dynamic Sections With Tailwind UI In A Laravel App. Some Ideas?

I'd say it's a many to many in this case.

If you have a pages table and a components table you create a component_page pivot table.

Then you take your page and attach the components

$page->attach($component->id);

More info can be found here

https://laravel.com/docs/8.x/eloquent-relationships#updating-many-to-many-relationships

Activity icon

Replied to How To Design The Relational Database For Inventory Asset Tracking Of Serialized And Bulk Items

I would use this kinds of database model

  • products
  • material_units
  • material_unit_contents

The product contains the information about the product such as part number, color, title, type and such. The material unit contains information about where it is and when it was created/recieved from the supplier. The material_unit_contents connects the product with the material unit. It has the current stock of that material unit.

So a product can have many material units through the material unit contents. By doing it this way you can have the quantity in different formats.

Let's say that you have two products.

Product 1 is a graphics card and you have ten pieces in two different material units. Product 2 is a network cat6 cable the you cut the length the customer wants.

You can use the same structure and you put a meassure of unit in the product table and the unit for the graphic cards can be pcs and the network cable cm.

You should also create a table for the measure_of_units so you can put a constrint on it in the products table.

When you sell a graphics card you decrease the quantity in the material_unit_contents table for the oldest material unit. unless of course you implement scanning of the material unit number you pick from.

Activity icon

Replied to Test Fails On Member Function Null

Have you installed SQLite 3?

Activity icon

Replied to Show Loading Progress For <video> HTML Element

The easiest way is to create a spinner

<section id="loading">
    <div id="loading-content"></div>
</section>
.loading {
	z-index: 20;
	position: absolute;
	top: 0;
	left:-5px;
	width: 100%;
	height: 100%;
    background-color: rgba(0,0,0,0.4);
}
.loading-content {
	position: absolute;
	border: 16px solid #f3f3f3; /* Light grey */
	border-top: 16px solid #3498db; /* Blue */
	border-radius: 50%;
	width: 50px;
	height: 50px;
	top: 40%;
	left:35%;
	animation: spin 2s linear infinite;
	}
	
	@keyframes spin {
		0% { transform: rotate(0deg); }
		100% { transform: rotate(360deg); }
	}
function showLoading() {
  document.querySelector('#loading').classList.add('loading');
  document.querySelector('#loading-content').classList.add('loading-content');
}

function hideLoading() {
  document.querySelector('#loading').classList.remove('loading');
  document.querySelector('#loading-content').classList.remove('loading-content');
}
Activity icon

Replied to Dynamic Sections With Tailwind UI In A Laravel App. Some Ideas?

You can create a component for each section using blade components.

https://laravel.com/docs/8.x/blade#components

in your page you just include the component

<x-compoent />

And pass the desired data to them

<x-component :message="$message"/>
Activity icon

Replied to How To Set Old() (flashed) Data When Testing Blade Components?

Something like this should work when creating.

/**
 * @test
 */
public function when_validation_fails_old_values_are_show,()
{
    $this->signIn();
    $artist = Artist::factory()->make(['name' => '']);

    $response = $this->post('/artists', $artist->toArray());

    $response->assertSee($artist->dob);
}

And something like this in updating

/**
* @test
*/
public function old_value_is_shown_when_validation_fails()
{
    $this->signIn();
    $artist = Artist::factory()->create();
    $artist->name = '';
    $this->patch('/artists/' . $artist->id, $artist->toArray());
    $this->assertSee($artist->dob);
}
Activity icon

Replied to Migration - Enter Columns Before Created_at And Updated_at Columns

If you still are in the development stage (not having put it to production) update the migrations instead of adding new ones.

Since there is no before option in SQL it's kinda tricky to acheive but since you should now the column before you should be able to use that.

From https://www.mysqltutorial.org/mysql-add-column/

Third, MySQL allows you to add the new column as the first column of the table by specifying the FIRST keyword. It also allows you to add the new column after an existing column using the AFTER existing_column clause. If you don’t explicitly specify the position of the new column, MySQL will add it as the last column.

Activity icon

Replied to Laravel Javascript, Add And Delete Table's Row Getting Jumpy

Not sure exactly what it is you want but something like this adds and removes rows in a html table.

<table>
<thead>
<tr><th>Field</th><th>Delete</th></tr>
</thead>
<tbody id="the-body"></tbody>
</table>

<button onclick="addRow()">Add</button>
let rows = 0;

function addRow() {
  rows++;
  const el = document.querySelector('#the-body');
  el.innerHTML += `<tr><td>${rows}</td><td><button onclick="deleteRow(event)">x</button></td></tr>`;
}

function deleteRow(event) {
	event.target.parentNode.parentNode.remove();
}
Dec
02
1 day ago
Activity icon

Replied to SQLSTATE Cannot Insert Null Values...

The naming convention for field names is catalog_number, I agree that it looks a bit of when you use camelcase in you variable and method names but it's there for a reason. SQL doesn't really care about the case so ´catalogNumberandcatalognumber` is the same thing most of the time. In some databases there is a difference when you create a table depending on if you use quotes or not which can lead to strange issues later on. So stick with lowercase letters and seperate the words with an underscore to avoid later headaches.

In your form you put a name to the input

<input type="text" name="title">

That name becomes the property used to access the value sent to the server.

You can access it like this

$request->title

Everything should be validated so you can do this

$validData = $request->validate(['title' => 'required']);

Then you need to create the record in the database which you can do like this

Model::create($validData);

The validation can be inlined like this

Model::create($request->validate(['title' => 'required']));

There are more than one way to do the above but that is one way to do it.

You need to allow for massassignment in your model and there are several ways to do that but since you are a good programmer and validate everything you can get away with

protected $guarded = [];

Which means you can assign all fields in the table.

Activity icon

Replied to Session Data As Array

The section above in the docs perhaps.

https://laravel.com/docs/8.x/session#storing-data

Activity icon

Replied to How To Hide All The Same Name Of Bank.Only Show First One

I take it you get the data from a database.

I suggest you filter it down there with a group by or in worst case a distinct.

Activity icon

Replied to OnDelete Cascade... Not Working, Some Help?

If you are using SQLite make sure you have enbled foreign key constraints.

Activity icon

Replied to Livewire Not Functionion

Not sure but shouldn't item be items on this line

return view('livewire.shoppingcart', ['item' => $this->Items]);
Activity icon

Replied to Don't View Content After Updating

Sounds a bit more like SBTW rather than an error on your side.

Activity icon

Replied to Don't View Content After Updating

Are you redirecting back or to the url?

Since just redirecting back doesn't always update, it uses the cached page.

Activity icon

Replied to Don't View Content After Updating

Lots of things can be wrong. Without more information it's impossible to help you.

Activity icon

Replied to Move A Laravel Application To An Offline Server

I take it you want to use laravel on a server that is not connected to the internet.

This guide will help you get up and running with the server and laravel. https://www.howtoforge.com/tutorial/install-laravel-on-ubuntu-for-apache/

You will need internet access to set it up but after that you can disconnect it from the internet.

Activity icon

Replied to Is Using GET Method Safe Since It Gets Cached?

Yes it caches some of the get requests like files and such but rest services are not cached in that way.

Activity icon

Replied to One Controller Method For Both Create & Update

In my opinion it's not a good idea to use the same method for both updating and creating. However createOrUpdate is the one you can use.

https://laravel.com/api/8.x/Illuminate/Database/Eloquent/Builder.html#method_updateOrCreate

Activity icon

Replied to Cache Clear In Production?

The only affect it will have is that the first request will take a tiny bit longer.

Activity icon

Replied to Laravel Deployment Related Question

Looks like you are hardcoding a path to where the logs are supposed to go somewhere in your settings.

"C:\wamp64\www\lms\storage\logs

I would check the .env file first.

Dec
01
2 days ago
Activity icon

Replied to SQLSTATE Cannot Insert Null Values...

This is most likely the issue.

"catalogNumber" => "123456"

it should be

"catalog_number" => "123456"

When naming fields in the database the words are seperated with an underscore.

Make sure the name of the field in your migration is catalog_number and that you have made the change in your form, validation and store method.

Activity icon

Replied to Nginx Point To Public

@jlrdw you might wanna check out Develop And Deploy Laravel Applications With Docker by https://twitter.com/aschmelyun.

https://gumroad.com/l/cwYKw

I watched the four or five first lessons and so far it looks really good.

Activity icon

Replied to Nginx Point To Public

Linux loves symlinks and they are good in *nix systems but on windows it better to copy the file to where it's supposed to be.

Activity icon

Awarded Best Reply on Nginx Point To Public

Yes it's Linux only but the part about the virtual host setting are still valid. You need to change some paths other than that you should be good.

Couldn't find a good one for windows though.

Activity icon

Awarded Best Reply on I Need To Decode Base64 Image To A Url Path And Save The Path In The DB Using Laravel API

This line like I said in my previuos comment

$data = base64_decode($base64_str);
Activity icon

Replied to Nginx Point To Public

Yes it's Linux only but the part about the virtual host setting are still valid. You need to change some paths other than that you should be good.

Couldn't find a good one for windows though.

Activity icon

Replied to I Need To Decode Base64 Image To A Url Path And Save The Path In The DB Using Laravel API

This line like I said in my previuos comment

$data = base64_decode($base64_str);
Activity icon

Replied to Laravel: Foreach Vs Filter + Pluck

Are you storing these products in the database?

If so always harness the power of the database to filter your data.

$products = Product::whereNotNull('category_id')->get();

When it comes to limiting the columns in your result use the database.

$products = Product::whereNotNull('category_id')`->pluck('weight');
Activity icon

Replied to Everything Blowed Up After Php 8.0

Have you checked that your global composer.json file don't have the php-cs-fixer in it still?