Tray2

Tray2

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

Member Since 5 Years Ago

Solna

Experience Points
218,420
Total
Experience

1,580 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
1226
Lessons
Completed
Best Reply Awards
156
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.

Level 44
218,420 XP
Dec
15
1 day ago
Activity icon

Replied to Laravel Hierarchy Users

So the desired reslt is something like

  • Steve (Manager)
  • Carol (Sales) $1000
  • Ben (Sales) $900
  • Aaron (Sales) $850

?

Activity icon

Replied to FFMpeg Executable Not Found

What is the output of which ffprobe?

When I run that command I see

/usr/bin/ffprobe
Dec
14
2 days ago
Activity icon

Awarded Best Reply on Retrieving Unique Row With Summed Quantity

Something along the lines of

SELECT product_id, variant_id, sum(item_qty)
FROM subscriptions
GROUP BY product_id, variant_id

?

Activity icon

Replied to Retrieving Unique Row With Summed Quantity

Something along the lines of

SELECT product_id, variant_id, sum(item_qty)
FROM subscriptions
GROUP BY product_id, variant_id

?

Activity icon

Awarded Best Reply on Adding Second Form Action With Button It Does Not Work

What is the button supposed to do?

If it's not to submit a from you need to add some javascript function to it.

Dec
13
3 days ago
Activity icon

Replied to Adding Second Form Action With Button It Does Not Work

What is the button supposed to do?

If it's not to submit a from you need to add some javascript function to it.

Dec
12
4 days ago
Activity icon

Replied to 404 Not Found

Does the Laravel welcome page work?

Activity icon

Replied to CSS Overlap

I suggest you use a prefix on one of them. Bootstrap might become bs. So to use it you do bs-row instead of just row.

https://stackoverflow.com/questions/29003264/customize-twitter-bootstrap-classnames

Dec
11
5 days ago
Activity icon

Replied to CSS Overlap

Not sure exactly what you mean but let's say you have a element with two classes

<style>
    .boxed {
        border: 1px solid black;
        border-radius: 5px;
    }

    .rounded {
        $border-radius: 10px;
    }
</style>

<p class="boxed rounded">

The above <p> would get rounded 10px corners.

If you change the order of the classes on the element.

<p class="rounded boxed">

It would get the 5px rounded corners.

You can use the !important keyword to override the default cascade.

    .boxed {
        border: 1px solid black;
        border-radius: 5px !important;
    }

That would make the above example use rounded 5px corners. This is a bad practice.

If you have the same class name in several of those files it will give you strange effects since they will all be added.

Dec
09
1 week ago
Activity icon

Replied to Using External API To Create Record Directly But DRY Way

I would probably use the same controller for both the "html" and the "api" way since they are the same.

Something like

public function store(Request $request)
{
    $movie = Movie::create($this->validate($request));
    $message = $movie->title . ' Successfully added';
    if($request->wantJson()) {
        return response()->json([
                'status => 200,
                'message' =>  $message
        ]);
        return redirect('/movies')->with(['message' => $message]);
}
Activity icon

Replied to How To Create Multi-pal Database Dynamically In Laravel

Something like

DB::getConnection()->statement('CREATE DATABASE :schema', array('schema' => $schemaName));

Should do the trick.

More info here https://laravel.io/forum/09-13-2014-create-new-database-and-tables-on-the-fly

Activity icon

Replied to Image And Video Processing Service

I'm guessing multi user setup?

Then you will need a dedicated host with lots of CPU, lots of memory, lots of diskspace and unlimited traffic. That is not cheap at all.

Activity icon

Replied to Weird Problem With Functions From Another Site

It should tell you on what row in your code it fails.

The code is barely readable so it's hard to understand what it does.

Activity icon

Replied to Multiple Tables

No.

Not until there is an actual insert into the table will the id be incremented and if a rollback occurs it will most likely just skip a number.

  • 1
  • 2
  • 4
  • 5

and so on.

Activity icon

Replied to Image And Video Processing Service

For images I'd use Intervention http://image.intervention.io/getting_started/installation#laravel

When it comes to video I'd use ffmpeg https://www.ffmpeg.org/

There is a laravel package for ffmpeg https://github.com/pascalbaljetmedia/laravel-ffmpeg

But like @fylzero says it's much easier to handle it on the local machine since it required lots of computing power to convert video.

You also need to be able to handle large uploads, lots of memory and a huge drive.

Activity icon

Replied to Passing Data From Database

I would create a service something like

Route::get('/someapi', '[email protected]');
public function someApi()
{
    return SomeApi::all()->toJson()
}
async function fetchSomeApi() {
    const response = await fetch('/someapi'); 
    const json = await response.json();
    document.querySelector('#somefield').value = json.somefield; 
}
Activity icon

Replied to Install Php

When using XAMPP you don't need to install PHP seperatly. You just need to add the path to the php.exe file to your computers path.

https://docs.alfresco.com/4.2/tasks/fot-addpath.html

Then you need to close your commend window and open it again. After that youhould be good to go.

Dec
08
1 week ago
Activity icon

Replied to Unique Validation For Two Columns When Editing A Resource.

I would do a check to see if the values are the same for the fields then return with a message.

Both in the backend and the frontend.

something like

public function(Category $category, Request $request)
if($category->title == $request->title) {
    return redirect->back()->withStatus('No changes made');
}

and

let isDirty = false;

document.querySelector('#title').addEvenListener('change', function() {
    isDirty = true;
});

document.querySelector('#category_form').addEventListener('submit', function(event) {

    if (isDirty) {
        event.perventDefault();
        console.log('No changes to save');
          }
});

I haven't tested the code so there might be some type-Os.

Activity icon

Replied to Two Laravel Project Access Same Images Assets Publicly

Or use a common S3 bucket to store the images.

Dec
07
1 week ago
Activity icon

Replied to Laravel Works With Artisan Serve But Not With Vhost

Have you activated mod_rewrite in Wamp?

Dec
06
1 week ago
Activity icon

Replied to Advice Please

So you mean something like

That you have a form with let's say three fields

And instead of having names like

  • first_name
  • last_name
  • age

They have names like

  • field1
  • field2
  • field3

And you get the labels from a table in the database.

The table has the following structure

  • id
  • field1
  • field2
  • field3

The table is named scenrios or something like it

So in your controller you load a random scenario

$scenario = Scenerio::all()->random(1);

In your view you can then do something like

<label for="field1">{{ $scenario->field1 }}</label>
<input type="text" name="field1">
Activity icon

Replied to Eloquent Query To Filter Same Column Values

Not sure that is possible but give this a try

$filter = $request->filter

$products = DB::table('product_filters')
                ->selectRaw("product_id WHERE pf.filter_id in ?' 
                             AND EXISTS (SELECT pfi.product_id  
                             FROM product_filter pfi 
                             WHERE pfi.product_id = pf.product_id 
                             AND pfi.filter_id in ?", $filter, $filter)
                ->get();
Activity icon

Replied to Eloquent Query To Filter Same Column Values

So you only want product_id 42?

SELECT pf.product_id
FROM product_filter pf
WHERE pf.filter_id = 2
AND EXISTS (SELECT pfi.product_id 
                      FROM product_filter pfi 
                      WHERE pfi.product_id = pf.product_id 
                      AND pfi.filter_id = 4);
Activity icon

Replied to Eloquent Query To Filter Same Column Values

Show me some example data from the table

Activity icon

Replied to Eloquent Query To Filter Same Column Values

Yes that query is fubar.

You want to get product filters that has the filter_id of 2 or 3.

In SQL I would do something like this

SELECT product_id
FROM product_filter
WHERE filter_id IN (2, 4);

In Eloquent the same query would look something like this

ProducFilter::whereIn('filter_id', [2, 4])->get();

And to make it more dynamic you just excehange the [2, 4] with a variable passed into the request something like

public function(Request $request)
{
     $filters = $request->filters;
     $products = ProductFilter::whereIn('filter_id', $filters])->get(): 
}

You should of course validate the request->filters before using it in your query

Activity icon

Replied to How Do I Get The Value From A Dropdown Menu To A Controller

In your case it should be $request->subject

Activity icon

Replied to One To Many

Well then show us the table structure and the models for them then.

Activity icon

Replied to It Is Possible Route A Url To Different Function?

You need to seperate the wildcards with a /

Route::get('{name}/{id}', [email protected]');

Be aware that it will catch any url in your app that has <something>/<something> in it.

Use

Route::get('products/{id}', '[email protected]');

instead.

Or even better name the Controller and the method like so

Route::get('products/{id}', '[email protected]');
Activity icon

Replied to One To Many

You can name it whatever you like but I'd use the convetion for and name in comments since it gets multiple comments and not just one.

That way your blade view gets more readable

Compare these two

@foreach($comment as $row)
    {{ $row->body }}
@endforeach

or

@foreach($comments as $comment)
    {{ $comment->body }}
@endforeach

I prefer the second one since I now know that we are working with comments and we do something for each comment. This might seem trivial in this case but if you have more fields you want to display it's easier to red without scrolling up to the beginning of the foreach to see what you are working with.

Activity icon

Replied to Tag In Detail Post Content

Yes and you should create a post_tags for the relation between them.

Activity icon

Replied to Combo Box

You need to change the $data2 to $data in your foreach.

@foreach($data2 as $ctg)
      <option value="{{ $ctg->id }}">{{ $ctg->ctg_name }}</option>
@endforeach
Activity icon

Replied to Combo Box

Dude you should know this by now...

Change

return view('admin.page.page')->with('list', $data);

to

return view('admin.page.page')->with(['list' =>  $data, 'data2' => $data2]);

I also highly suggest you change the variable names $data and $data2 to something more descriptive.

The view code seems ok.

Activity icon

Replied to Tag In Detail Post Content

I suggest you use another database structure for this

You need three tables

  • posts
  • tags
  • post_tags

You store each tag as a record in the tags table then you use the pivot table post_tags to link the post and tag. A classig many to many relationship.

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

Activity icon

Awarded Best Reply on Migrate

If you have a migration file named create_some_table then Laravel is looking for a class named CreateSomeTable so when you rename the file to create_some_other_table you need to rename the class as well or Laravel will not find CreateSomeOtherTable.

Activity icon

Replied to Migrate

If you have a migration file named create_some_table then Laravel is looking for a class named CreateSomeTable so when you rename the file to create_some_other_table you need to rename the class as well or Laravel will not find CreateSomeOtherTable.

Activity icon

Replied to My Variable Is Not Being Passed To My View

Or you can do this

 return view('pages/pastpapers/igcse')->with([
    'paper' =>$paper,        
        'pastpapers'=> $pastpapers,
        'items' => $items,
        'filter' => $filter
]);

Since you are mixing plural and sigular in your code make sure you have the same variable names in your view.

Activity icon

Replied to MySQL Trigger To Keep Num_comments (across A Nested Comment Tree) Up-to-date When A Comment Is Inserted / Deleted

As I see it there are two ways to acheive this with as little headache as possible.

  1. Store the stats in it's own table
  2. Use a view to calculate on the fly

If we start with the first one you create a table that has the following fields

  • id
  • comment_id
  • number_of_comments

Then you can update the number of comments with your trigger.

The second we can create a view that on the fly calculates the number of comments

CREATE OR REPLACE VIEW comment_stats AS
SELECT c.id AS comment_id, count(*) AS number_of_comments
FROM comments
GROUP BY id

This is a bit over simplified when you add nesting. To solve that you need to add the "parent" to the view as well.

Activity icon

Replied to Slow Response After Clicking Add Button In Laravel

Do you have the proper indexes on offices and students?

From a quick run through it seems like you need to have indexes on

  • transactions.office_id
  • students.rfid
  • offices.letter
Dec
05
1 week ago
Activity icon

Replied to Intervention Image Problem

500 means that something went wrong.

If one image size works and not another it sounds to me that there might be a limitation of either the file size or the memory available for php.

Check these values in you php.ini

  • upload_max_filesize The maximum allowed upload file size.
  • post_max_size The maximum allowed POST data size.
  • max_input_time Maximum allowed input time.
  • max_execution_time The maximum allowed time the scripts are allowed to run.
Dec
04
1 week ago
Activity icon

Replied to Auto Increment ID For Each Client Of The User

If you want to do something like that (which I advice against) you can do something like

Clients Table

  • id
  • user_id
  • client_no

and some client info fields.

Then you ignore the id and use the client_no instead as your counter.

That would mean you need to get the max client_no for that user every time you create a new client.

Something like

$clientNo = Client::where('user_id', Auth::user()->id)->count(); + 1;
 Client::create([
    'user_id' => Auth::user()->id,
        'client_no' => $clientNo
]);
Activity icon

Replied to Handling Over 7k Records, GroupBy And Pagination

I would create a view that represents the data set and paginate from that.

CREATE OR REPLACE VIEW some_view AS
SELECT some_field, sum(some_other_field)
FROM some_table
GROUP BY some_field;

Then I can run a simple Eloquent query on it

$result = SomeView::paginate(25);

This example is very simplified.

You can use a migration to create the database view

In your up() method

DB::statement("CREATE OR REPLACE VIEW some_view AS
SELECT some_field, sum(some_other_field)
FROM some_table
GROUP BY some_field");
Dec
03
1 week ago
Activity icon

Replied to How To Pass Parameter Value To 2 Different Functions In Same Controller?

You use parameters.

Function one calls function two with an argument.

Procedural way:

function one()
{
    $foo = 'Some value';
        two($foo);
}

function two($value)
{
    store($value);
}

OOP way

public function one()
{
    $foo = 'Some value';
    $this->two($foo);
}

public function two($value)
{
   store($value);
}

If you don't know how to pass arguments between functions in PHP I suggest you learn the basics of PHP before you start using Laravel.

Activity icon

Awarded Best Reply on Collections - Each Method

How do you populate the collection?

If it's from a table in the database it's much better to let the database handle the filtering.

Otherwise you can try forget

https://laravel.com/docs/5.7/collections#method-forget

Activity icon

Replied to Collections - Each Method

How do you populate the collection?

If it's from a table in the database it's much better to let the database handle the filtering.

Otherwise you can try forget

https://laravel.com/docs/5.7/collections#method-forget

Dec
02
2 weeks ago
Activity icon

Replied to Laravel Valet Broken After Upgrading To PHP 7.4

Did exactly that this weekend and took me about two hours to get it back up again.

Not sure what made it run again but I ran the following

brew uninstall [email protected]

brew uninstall nginx

brew uninstall dnsmasq

brew install php

brew install nginx

brew install dnsmasq

sudo valet install

Good luck.

Activity icon

Replied to Very High CPU Usage With Laravel-5.2

That is hard to predict but a proper stack uses less resources than xampp.

This document might shed some light.

https://www.dynatrace.com/news/blog/7-minute-workout-does-your-apache-web-server-need-love/

Activity icon

Replied to How To Get The Current With Previous Value Of An Array?

Not knowing exactly what you mean but something like this maybe?

@foreach($records as $record)
    @if(! $loop->first())
        {{ $records[$loop->index -1]->value }}
    @endif

    {{ $record->value}}
    
    @if(! $loop->last())
        {{ $records[$loop->index +1 ]->value }}
    @endif
@endforeach
Activity icon

Replied to Get Sku Less Then 13 Digit

What is the error message?

Activity icon

Replied to Very High CPU Usage With Laravel-5.2

@omkark610 I wouldn't use XAMPP in a production like environment since it's mostly for development. I suggest you set up a proper stack lemp or lamp.

https://www.howtoforge.com/perfect-server-debian-10-nginx-bind-dovecot-ispconfig-3.1/

https://www.howtoforge.com/perfect-server-debian-10-buster-apache-bind-dovecot-ispconfig-3-1/

Regardning the high CPU load it's probably due to the sql that is getting run. Without any code example it's hard to see the reason for it but it might be poorly written SQL and or missing indexes.

Take this simple query for example

SELECT * FROM some_table WHERE created_at BETWEEN '2019-12-01' AND'2019-12-02';

If you don't have an index on created_at it will scan every record in your table. When you add an index it will maybe read 10 records intead of thousands.

Oh and by the way, please don't hijack threads that are years old. Create a new one instead.