Tray2

Tray2

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

Solna

Member Since 4 Years Ago

Experience Points 116,260
Experience
Level
Lessons Completed 1026
Lessons
Completed
Best Reply Awards 38
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

04 Nov
1 month ago

Tray2 left a reply on Htmlspecialchars() Expects Parameter 1 To Be String, Array Given (View: D:\fyp\New Folder\bidbazar\resources\views\welcome.blade.php)

$node is an array.

Do a ´dd($node)´ and check the keys available.

And when you know that you can

{{ $node->key }}
31 Oct
1 month ago

Tray2 left a reply on Dynamically Change Table Name Depending On Language

That is a bad idea in my opinion. It's much better to add a country identifier to the table.

28 Oct
1 month ago

Tray2 left a reply on Class 'Tests/TestCase' Not Found When Attempting To Run Test

It's very simple.

  1. Install Laravel composer create-project laravel/laravel myniftyproject
  2. cd myniftyproject
  3. ./vendor/bin/phpunit
27 Oct
1 month ago

Tray2 left a reply on How To Order By "most" Of Something From The Pivot Table?

I would go with an SQL solution for this.

select * 
from
(select u.username,
            (select count(*)
            from follower_user 
           where fu.user_id = u.id) followers)
order by followers desc;

Something like that should work baring type-os.

Tray2 left a reply on Cmd Error

Have you run these three commands? <project-name> should be your project name.

  • composer create-project laravel/laravel <project-name>

  • cd <project-name>

  • php artisan

Tray2 left a reply on Artisan Command

I don't think you can do that out of the box.

Check this link for a workaround.

https://stackoverflow.com/questions/30287896/rollback-one-specific-migration-in-laravel

Tray2 left a reply on SQLSTATE[28000] [1045] Access Denied For User 'root'

In your .envfile you need to change the user name and password for mysql. The user root does not exist on the shared host and even if it did the password should never be empty.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mediabase
DB_USERNAME=root
DB_PASSWORD=

Need to be updated to your password and username that you have on the shared hosting.

Tray2 left a reply on Database Sync

It's something you setup in MySQL so that it stores the changes in a log. See the mysql manual on how to do this.

If these logs are stored in place where laravel can get to them then you should be able to push them onto your remote server. Then you can run some queue job on the remote machine to sync the machine.

This is highly experimental and nothing I've ever tried doing so it might not be possible.

Tray2 left a reply on Database Sync

Depending on your setup there are a few ways to do this.

  • Use mysqldump to export the local database and then import it on the hosted.
  • Use binary loggin on the local machine and apply the logs to the hosted machine.
  • Setup mysql for replication

The code to do any of these with a button click you have to write your self.

If it's a onetime thing I'd do the mysqldump if you need to sync avfew times a day you could use the binary method.

If you need to keep them synced all the time you need to use replication. http://www.clusterdb.com/mysql-cluster/get-mysql-replication-up-and-running-in-5-minutes

26 Oct
1 month ago

Tray2 left a reply on Error Migration

I'm not sure about the support for Oracle databases in Laravel or PHP for that matter. However the error message states that you are trying to create a sequence that already exists and it probably has a name similar to zr04 which by the way is a terrible name.

I suggest you connect with SQL Developer and find the sequence and drop it or drop it with drop sequence sequence_name.

25 Oct
1 month ago

Tray2 left a reply on Creating A Search Function With Multiple Filters

Something like this should work

Vehicle::where('type', 'like', '%' . $type)->whereBetween('price', [$minPrice, $maxPrice])->get();

Tray2 left a reply on Mysql Query Raw To Laravel Eloquent

There is no need to use eloquent for everything. I use it for simple queries but more complex ones I use DB:select or DB:raw.

Tray2 left a reply on Command Line For Import

ERROR 1050 (42S01) at line 29: Table 'access_permissions' already exists

Either you drop the table or you comment out the creation in your SQL file.

23 Oct
1 month ago

Tray2 left a reply on One Column With Data Array

Does your view have the .blade.php extension?

22 Oct
1 month ago

Tray2 left a reply on One Column With Data Array

You need to wrap them in anchor tags like I did in my example.

Tray2 left a reply on One Column With Data Array

Something like this should work.

@foreach($files as $file)
    <a href="{{ $file->path }}">{{ $file->name }}</a>
@endforeach
21 Oct
1 month ago

Tray2 left a reply on Authorization User Or Guest Show!

You use three backticks `

Do I understand correctly that you want to display Guest when not logged in? In that case just add an @elseto your @if

@if(Auth::check())
     Welcome: {{ Auth::user()->name }}
@else
    Welcome Guest
@endif 

Tray2 left a reply on How To Fix NotFoundHttpException No Query Results For Model [App\Upload] 8

What does your edit method in your controller look like? That message is probably due to there not being any record with the id of 8 in your table.

20 Oct
1 month ago

Tray2 left a reply on Is This A Hack Way Of Implementing Different Types Of Accounts

I would not do that. I would use KISS and just protect the admin routes with a middleware so that only admins can access them instead.

Tray2 left a reply on How To Increase UTF-8 Emoji Size Without Increasing Text Front Size

Since an emoji is text you can only change it's size by increasing the font size. I suggest wrapping it in a span and give it a class where you set the appropiate font size.

Tray2 left a reply on ->groupBy('new') How To Get Group By Get First Record Id

And you are writing your query how?

19 Oct
1 month ago

Tray2 left a reply on Include Min Max In Pagination Count Query

Then use db::select and write in in plain SQL.

DB::select('SELECT *, max(price) max_price, min(price) min_price, (SELECT count(*) FROM products WHERE active = 1) quantity FROM products offset = :offset and limit = 20', ['offset' => $offset]);

or somesuch.

Tray2 left a reply on Include Min Max In Pagination Count Query

You can always do

$products->max('price');
$products->min('price');

but that is only on the selected 20.

or you can have a method maxPrice in your products model.

public function maxPrice()
{
 return Product::where('active', 1)->max('price');
}

Tray2 left a reply on Is To Build Own Image Nude Checker In Laravel

I would say nearly impossible to get it working flawlesly.

Tray2 left a reply on Include Min Max In Pagination Count Query

Is it something like this you are looking for?

SELECT count(*), min(field), max(field)
FROM table;

Tray2 left a reply on Session::get To Include Goes Not Bring Back Data

Is the file named flash_message.blade.php and placed in the resources/views/includes directory?

Tray2 left a reply on Is To Build Own Image Nude Checker In Laravel

Are you talking about a function that checks the image to see if it contains nudity? If so then don't build it yourself it's very compicated.

Tray2 left a reply on Validation On Update: Unique

Where do you load the user that you want to update into $user?

try dd($user); in your update method and show the output

Tray2 left a reply on Validation On Update: Unique

Show us your update method.

Sounds to me like you are inserting another record with the same email instead of updating the value of an existing one.

18 Oct
1 month ago

Tray2 left a reply on Installation Problem

Whgen you run the command do you see this?

composer create-project laravel/laravel test
Installing laravel/laravel (v5.7.0)
  - Installing laravel/laravel (v5.7.0): Downloading (100%)
Created project in test

Tray2 left a reply on Need To Add The Shipping Cost Based On Cart Item Quantity.

If you do a collection of the items then you can do something like this.

$items = collect($itemsArray);
$totalCost = $items->sum('price') + $shippingCost;

Tray2 left a reply on Need To Add The Shipping Cost Based On Cart Item Quantity.

I would do something like this for the shipping calculation.

$initialCost = 200;
$shippingCost = $initialCost + ($qty -1) * 100 ;
16 Oct
1 month ago

Tray2 left a reply on Encrypted Columns

I don't really see the need to encrypt/decrypt the whole database. Just encrypt sensitive data like passwords, credit card numbers and such.

However check this link https://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html

Tray2 left a reply on Is This The Right Way Of Deleting A Record That Belongs To This User?

That works but you can also use

public function destroy(Request $request)
{
   $user = User::findOrFail($request->id);
   $user->delete();
   return redirect('/users');
}

or

public function destroy(User $user)
{
  $user->delete();
  return redirect('/users');
}
14 Oct
1 month ago

Tray2 left a reply on Allowed Memory Size Of 134217728 Bytes Exhausted

Show us some code and we might be able to help you.

Tray2 left a reply on Grouping By 'date' Field

Is the query still giving you the same result when you do a dd($dates);?

Tray2 left a reply on How To Remove Similar Objects Using Checking A Field Of Those?

Try

$array = array_unique (array_merge ($array1, $array2));

Tray2 left a reply on 404 Sorry, The Page You Are Looking For Could Not Be Found.

What does your routes file look like and are you sure you get any data back from your query?

13 Oct
1 month ago

Tray2 left a reply on App\Users::find(2) Vs App\Users::where('id',2)->get()

The first one gets a eloquent collection and the other an array.

Tray2 left a reply on How To Update Table Values From 0 To 1 When I Click Form Submit Button In Laravel?

In your controller you have something like.

public function update(Request $request)
{
   $vehicle = Vehicle::findOrFail($request->id);
   $vehicle->adtype = request->adtype;
   $vehicle->update()
   return 'Some proper response';
}

Then you can either to a regulat form request or an ajax request to your route.

Tray2 left a reply on Installation Problem

How do you install Laravel?

Do you use the Laravel installer or do you use composer create-project?

What arguments are you supplying?

Tray2 left a reply on How To Check String Have Any Link Or Not, And Add Anchor Tag On It

I would do something like this.

  • Strip any anchor tags before saving the link to the database.
  • Insert the link text into the anchor tag in my view.
//Controller store and update methods
$model->link = strip_tags($request->link);

//view
<a href="{{ $model->link }}">{{ $model->link_text }}</a>
12 Oct
1 month ago

Tray2 left a reply on Split Data From Database Column & View As String

You do the explode in the controller then you pass it to the view

return view('model.action', compact('array'));

then in you view you loop over the array and place them fields.

@foreach($array as $rec)
    <input type="text" value="{{$rec}}">
@endforeach

Or something similar.

Tray2 left a reply on What Other Way Can This Query Be Written To Avoid High Server Resource Consumption

Agreed indexes is a must since you want to avoid full table scans.

Tray2 left a reply on Split Data From Database Column & View As String

$array = explode(',', $model->field);

You might wanna trim the values too.

11 Oct
1 month ago

Tray2 left a reply on Advice For Relationship Between Album And Artist (music Stuff)

Depends a bit on how advanced you want to make it.

The KISS way.

Artist has many albums album belongs to artist

The less KISS way.

Artist has many albums Album has many artists

Then of course you can have track artists and so on .

I suggest starting with the kiss way in your tests then make it more advanced as you proceed.

I did this with books and I started with a single table and as the app progressed is created seperate tables and relations.

10 Oct
1 month ago

Tray2 left a reply on Phpunit Testing Form Validation

I usually do my validation tests like this.

The happy path test

    /** @test */
    public function a_valid_author_can_be_stored()
    {
        $this->withoutExceptionHandling();

        $author = factory(Author::class)->make([
          'first_name' => 'Robert',
          'last_name' => 'Jordan'
      ]);

        $response = $this->post('/authors', $author->toArray());

        $response->assertStatus(200);
        $this->assertEquals(1, Author::count());
    }

Test that the first field is required

    /** @test */
    public function authors_first_name_is_required_to_store_an_author()
    {
        $author = factory(Author::class)->make([
          'first_name' => null,
          'last_name' => 'Jordan'
      ]);

        $response = $this->post('/authors', $author->toArray())->assertSessionHasErrors(('first_name'));

        $this->assertEquals(0, Author::count());
    }

Check that the second field is required

    /** @test */
    public function authors_last_name_is_required_to_store_an_author()
    {
        $author = factory(Author::class)->make([
          'first_name' => 'Robert',
          'last_name' => null
      ]);

        $this->post('/authors', $author->toArray())->assertSessionHasErrors(('last_name'));

        $this->assertEquals(0, Author::count());
    }

Test some other rule

    /** @test */
    public function authors_name_must_be_unique_to_store_an_author()
    {
        $author = factory(Author::class)->create([
            'first_name' => 'Robert',
            'last_name' => 'Jordan'
        ]);

        $author = factory(Author::class)->make([
              'first_name' => 'Robert',
              'last_name' => 'Jordan'
          ]);

        $this->post('/authors', $author->toArray())->assertSessionHasErrors(['first_name' => 'Author name not unique']);

        $this->assertEquals(1, Author::count());
    }

Hope this gives you some direction.

07 Oct
2 months ago

Tray2 left a reply on Laravel Official Form Builder

I missed it to when it was removed but now it feels more like I'm in control over my form and it's a bit faster not to have blade convert it to html every time.

Tray2 left a reply on Avatar Or Image Saved In A $variable Directory

I would not let a random user create directories on my server like that.

I would create a table that contains the id, path and directory_id and another table containing all the directory descriptions. Then I would create more directories when needed. say every x thousand uploads.

So your directory structure would be something like this

1
    1.jpg
    2.jpg
    ...
    1000.jpg
2
    1001.jpg
    1002.jpg
    ...
    2000.jpg

That way the user can't create strange dirctories and potenntionaly break your site.