Tray2

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

Experience

109,970

35 Best Reply Awards

  • Member Since 3 Years Ago
  • 986 Lessons Completed
  • 0 Favorites

14th October, 2018

Tray2 left a reply on Allowed Memory Size Of 134217728 Bytes Exhausted • 1 day ago

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

Tray2 left a reply on Grouping By 'date' Field • 1 day ago

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? • 1 day ago

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. • 2 days ago

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

13th October, 2018

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

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? • 3 days ago

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 • 3 days ago

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 • 3 days ago

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>

12th October, 2018

Tray2 left a reply on Split Data From Database Column & View As String • 3 days ago

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 • 3 days ago

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 • 3 days ago

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

You might wanna trim the values too.

11th October, 2018

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

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.

10th October, 2018

Tray2 left a reply on Phpunit Testing Form Validation • 5 days ago

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.

7th October, 2018

Tray2 left a reply on Laravel Official Form Builder • 1 week ago

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 • 1 week ago

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.

Tray2 left a reply on Grouped By • 1 week ago

Something like

//Controller
$product = Product::findOrFail($id);


//View
{{ $product->comments->latest() }}

//Product model
public function comments()
{
    return $this->hasMany(Comment::class);
}

//Comment Model
public function latest()
{
    return Comment::where(product_id, '$this->product_id)->latest();
}

I haven't tried the code but something similar to it should work.

Tray2 left a reply on Dependent Dropdown From Same Table • 1 week ago

If it's the same table you need some kind of hierachy like.

|id|item|parent_id| |--|-------|------------| | 1| Country | | | 2| City | 1|

Then you can get all the records where the parent_id is null for one dropdown. Then you can use ajax to load the data into the second dropdown based on the selected id = parent_id

Tray2 left a reply on General Error: 1205 Lock Wait Timeout Exceeded In Nova Action • 1 week ago

I'm not sure since I have not tested Nova at all or used database transactions in Laravel.

Tray2 left a reply on Dependent Dropdown From Same Table • 1 week ago

Not sure what you are after here but to make a dropdown populated by the database I do something like this.

//Controller

public function index()
{
    $models = Model::All();
    return view('model.index', compact('models');
}

//View

<select>
    @foreach($models as $model)
        <option value="{{ $model->id }}">{{ $model->field }}</option>
    @endforeach
</select>

Tray2 left a reply on Admin/dashboard Not Defined On Redirectif Authenticated Route Error On Lcoalhost\login • 1 week ago

You are using named routes in your redirect. Do you have those named routes defined in your web.php file?

Route::get('/admin/dashboard', '[email protected]')->name('admin.dashboard');

Tray2 left a reply on General Error: 1205 Lock Wait Timeout Exceeded In Nova Action • 1 week ago

Not sure this is relevant here but...

If database transactions are used then every time you do an update on a value it follows this routine.

  1. Select the row for update
  2. Update the value
  3. Commit or rollback the change (releases the lock)

So if I am in the process of updating a record and you try to do the same then you will get a error stating that the record is locked.

If the record is locked the database will wait for it to release if it takes to long it will timeout.

I'm not sure they exists in MySQL in Oracle you can use NOWAIT SKIPPED LOCKED to handle this.

5th October, 2018

Tray2 left a reply on User Editable Templates • 1 week ago

I'd go with KISS in this case and make one view (blade file) for each model (table) unless of course some can house multiple models like say author and book. Then you can combine them but it there are no natural connection between the models.

This is what MVC is about.

Tray2 left a reply on DB Query Question • 1 week ago

If there can be more than one event on the location then they "should" be seperate tables otherwise you will get quite redundant. That being said, no you wont have any speed issues if you use indexes properly.

Tray2 left a reply on Phone Number Format • 1 week ago

Something like this should work.

In your model.

function getPhoneNumberAttribute()
{
    $cleaned = preg_replace('/[^[:digit:]]/', '', $-this->phone);
    preg_match('/(\d{3})(\d{3})(\d{4})/', $cleaned, $matches);
    return "({$matches[1]}) {$matches[2]}-{$matches[3]}";
}

Then you can call it

{{ $admin:applist->phoneNumber }}

4th October, 2018

Tray2 left a reply on How To Check Which Button Has Been Click From Controller • 1 week ago

Then you arte not passing the button to your request.

If you do a dd($request->button it will give you null.

I'm not a jQuery guy but here is where you need to add on which button was pressed.

onclick="event.preventDefault();document.getElementById('submit- 
            form-personal').submit();">

Tray2 left a reply on Retrive Laravel Session Data With Native Php • 1 week ago

I don't think it's even possible to share session. If it is, I really don't recommend it due to security issues.

Tray2 left a reply on Diplaying DB Select To Blade • 1 week ago

In your controller you need to pass the result as an array.

return view('users.index', compact('users');

That is probably the reason why it fails but since you haven't provided us with the controller I can't say for sure.

Tray2 left a reply on How To Check Which Button Has Been Click From Controller • 1 week ago

Since you use javascript to send the form just add the button name to the params you send and then check which button it is.

if ($request->button == 'this') {
   //Do this
} else {
  //Do that
}

Tray2 left a reply on Validate Dates Before Saving • 1 week ago

$end = Carbon::parse($request->input('end'));
$start = Carbon::parse($request->input('start'));

$length = $end->diffInDays($now);

Then you can check that lenght = 6.

Tray2 left a reply on How To Check Which Button Has Been Click From Controller • 1 week ago

I agree with @D9705996 that it's a good way to solve it.

You can also give the buttons different names and pass them in the request to your controller.

Tray2 left a reply on Uncaught ReferenceError: UPLOADTIME Is Not Defined • 1 week ago

You are trying to use variables before they are assigned. You are using all CAPITALS like they are constants instead of variables.

Having no idea what you are trying to do so it's impossible for us to help you. My guess is that the problem is in this code.

        // var UPLOADTIME, ALBUMART, ARTIST_URL, ARTIST, TITLE_URL, TITLE, WAVEFORM, STREAM;

        var playerTemplate = '<div class="customplayer"><div class="uploadtime">'+UPLOADTIME+'</div><div class="albumart" style="background-image:url('+ALBUMART+');"></div><div class="player"><button type="button" class="play-button btn btn-default btn-lg"><span class="play glyphicon glyphicon-play"></span><span class="pause glyphicon glyphicon-pause" style="display: none;"></span></button><div class="metadata"><div class="artist"><a target="_blank" href="'+ARTIST_URL+'">'+ARTIST+'</a></div><div class="title"><a target="_blank" href="'+TITLE_URL+'">'+TITLE+'</a></div></div><div class="waveform"><div class="waveformimage" style="background-image: url('+WAVEFORM+');"></div><div class="played"></div></div></div><audio class="audioplayer" src='+STREAM+' preload="none"></audio></div>';

        var formatters = {UPLOADTIME : timeSince(new Date(json.created_at)),
            ALBUMART : json.artwork_url ? json.artwork_url.replace('-large', '-t200x200')
                : json.user.avatar_url.replace('-large', '-t200x200'),
            ARTIST_URL : json.user.permalink_url,
            ARTIST : json.user.username,
            TITLE_URL : json.permalink_url,
            TITLE : json.title,
            WAVEFORM : json.waveform_url,
            STREAM : json.stream_url + '?client_id=' + config.sc.clientID};

3rd October, 2018

Tray2 left a reply on ErrorException (E_ERROR) Undefined Variable: Company • 1 week ago

Please mark the reply that helped you solve the issue.

Tray2 left a reply on ErrorException (E_ERROR) Undefined Variable: Company • 1 week ago

There is a ' missing in the array.

['company=>$company']

should be

['company' =>$company]

Tray2 left a reply on Inserting Data - OneToOne RelationShip • 1 week ago

No code visible here but that message usually means that you have not created an object of the model you are trying to save.

$post = new Post();
$post->title = 'Some nifty title';
$post->body = 'The nifty text';
$post->save();

You can then create another object of the other table and do the same thing or create a method for it in the post class. Then you can call it like `$post->statistics->store($request);' or somesuch.

Tray2 left a reply on ErrorException (E_ERROR) Undefined Variable: Company • 1 week ago

Show us the CompaniesController's show method. It should look something like this where you pass the result of the query to the view.

public function show($id)
{
    $company = Company::findOrFail($id);
    return view('companties.show', compact('company');
}

Tray2 left a reply on Post Route Doesnt Work • 1 week ago

Like Cronix said use lower case on post

Route::post('/ImportUsersFile', '[email protected]')...

I would also suggest adding / infront of the desired url.

Tray2 left a reply on Password Protect A Deployed Site That Uses Authentication So A Client Can See, But No One Else. • 1 week ago

I would not play around with that kind of authentication but rather host the site somewhere secure (not on the public web).

Either on a server on the clients intranet which is only accessible from their network or put it behind a VPN on a machine you host. Or even take it as far as to put it on a virtual host running lamp/lemp that the can have on their local machines.

Tray2 left a reply on Blade Directive To Handle Conditional Content Hierarchy? • 1 week ago

You can always do something like

@foreach(Auth::user->allowedAction as $action)
    {{ $action->link }}
@endforeach

Tray2 left a reply on Blade Directive To Handle Conditional Content Hierarchy? • 1 week ago

If I understand you correctly you mean that the content of a variable is either this or that then print it's contents?

@if($variable == 'this' || $variable == 'that')
    {{ $variable }}
@endif

Tray2 left a reply on Speed Up Unit Tests • 1 week ago

Since I run single test 99.9% of the time and only run the whole suite once in a while I think 5.3 seconds is fast enough 85 tests and 283 assertions. :)

Tray2 left a reply on Get The Value Of An Associative Array Object • 1 week ago

If you $task array has this value

$task = ['complete' => true];

You can use

if($task['complete']) {
  echo 'Task complete';
} else {
  echo 'Task not complete';
}

If the value is 0 or 1 use

if($task['complete'] == 1) {

This is standard PHP and if you don't know the basics don't dive in to the Laravel world just yet. Wait until you learned the php basics.

Tray2 left a reply on Get The Value Of An Associative Array Object • 1 week ago

The easiest is to use $task['complete']or you can make a collection of it then use ยด$task->complete`

Tray2 left a reply on Speed Up Unit Tests • 1 week ago

I use and in memory sqlite database when doing my testing.

PHPUnit 7.3.4 by Sebastian Bergmann and contributors.

................................................................. 65 / 85 ( 76%)
....................                                              85 / 85 (100%)

Time: 5.24 seconds, Memory: 26.00MB

OK (85 tests, 283 assertions)
PHPUnit 7.3.4 by Sebastian Bergmann and contributors.

................................................................. 65 / 85 ( 76%)
....................                                              85 / 85 (100%)

Time: 5.27 seconds, Memory: 26.00MB

OK (85 tests, 283 assertions)

Add these two lines to your phpunit.xml

        <env name="DB_CONNECTION" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:"/>

1st October, 2018

Tray2 left a reply on 3 Relations On Pivot Table • 2 weeks ago

It's not mandatory to use Eloquent everwhere. A simple query as the one I wrote can be very complicated in Eloquent. I usually use Eloquent for the easier more readable stuff and for the more complex I use raw SQL. If the query is really complex I might even create a view in the data base and then run eloquent against the view.

In your case it's the lack of relationship you want.

Something like this might be possible.

$images = Images::whereNotIn('id', Pivot::all());

Tray2 left a reply on Laravel Query Builder • 2 weeks ago

Those records are not duplicate since the rollnum is not the same and the id makes it complex.

If the were the same you could use distinct.

SELECT DISTINCT name, age FROM table;

Tray2 left a reply on 3 Relations On Pivot Table • 2 weeks ago

Something like

SELECT * 
FROM images
WHERE id NOT IN (SELECT image_id FROM pivot);

Should work

Tray2 left a reply on Date Formating For Database Storage. • 2 weeks ago

I agree with @Cronix.

There is no reason what so ever for the client to care what format you have in the database and most "SQL Editors" can display it in the format they like regardless of what's in the database.

30th September, 2018

Tray2 left a reply on Radio Button Array Store • 2 weeks ago

Then put the onclick on the send button.

I would have put it on the radio button and handle each book as a seperate instance.

I would probably also use a number input or a dropdown instead of radio buttons since it's more than two values to choose from.

Tray2 left a reply on Cast ROUNDed Value To Decimal • 2 weeks ago

Exactly

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.