UAVova

UAVova

Member Since 2 Years Ago

Experience Points 3,330
Experience Level 1

1,670 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 23
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.

17 Mar
1 year ago

UAVova started a new conversation Laravel_session Changing With Every Page Refresh

Maybe i'm missing something but should the laravel_session i nthe cookies change after every page request?

I'm refreshing same page (http://localhost) and for every page refresh i'm receiving new laravel_session cookies.

First page refresh:

eyJpdiI6IlRxSzd4enlEQVRrSWRaTktHcXU1M0E9PSIsInZhbHVlIjoiQWVOZEZhOFEzekRLS2Rid1E1cGM0djltYWRCbmVrbFl5ZVoySmh0a2xwc1ZsNFhyVXdvT3oxK3J1RlJxTUJrN1Q1ckR5SkV0ZWh4bFhVbWpNa1NuV3c9PSIsIm1hYyI6IjNlYTA3ZDk1YTI0OGI1OGUyNDkyYzZjMWQ2YjYxODU4OGNmNzhhNjAyN2IwOTJlZjg5NGZhMzBkNTlhYTNiNjEifQ%3D%3D

Second page refresh:

eyJpdiI6IkpDaWJxd0Z4dFZWc0VBQWx2aHFuckE9PSIsInZhbHVlIjoiWXp0Z0MyU3Nzc1g4Tk13akkwZ2hrU040a0Z6d2RzMnRuM2NEZ2xjSnFDbk9PQmF4RXdNY3JaK0dHVnRXODh1NkpwRUlWS1J3ajM4TkwxeThnUGFsUHc9PSIsIm1hYyI6IjdlNjU1Mzg3MzM3MmQyNWIyNTFjZDQ0YjFlOGQzYzMzN2U1N2ZiNDU3MGQ5OTEzYjYyZjA2MGJjNWZhNjczYjQifQ%3D%3D

Is it normal?

14 Mar
1 year ago

UAVova started a new conversation ResourceCollection Doesn't Include Pagination Links.

CommentsCollection

class CommentsCollection extends ResourceCollection
{
    public function toArray($request)
    {
        return [
            'data' => $this->collection
        ];
    }
}

CommentsController

public function index()
{
    $post = Post::find(1);
    return ['post'=> $post, 'comments' => new CommentsCollection(Comment::paginate(1))];
}

Response

"comments": {
        "data": [
            {
                "id": 1,
                "content": "First comment",
                "post_id": 6,
                "account_id": 1,
                "created_at": "2018-03-07 02:50:33",
                "updated_at": "2018-03-07 02:50:34"
            }
        ]
    }

So, this happens when resource with use of ::collection method or even ResourceCollection returned as a part of the array.

If we gonna remove array and return pure resource like return new CommentsCollection(Comment::paginate(1)), everything is going to work fine and response will include meta and links.

Why does API Resource (using collection method or ResourceCollection) doesn't include pagination information when returned in array?

18 Jul
2 years ago

UAVova started a new conversation Missing Item In Laravel APi

Recently, i want to learn about Gate facade API, but it seems to be missing int the list https://laravel.com/api/5.4/Illuminate/Support/Facades.html .

BUT, if you manually visit link https://laravel.com/api/5.4/Illuminate/Support/Facades/Gate.html - it open successfully.

It is a bug?

08 Jul
2 years ago

UAVova started a new conversation Strange 5.4 Documentation

Hey there! Recently i viewed new laravel 5.4 documentation and got confused right from the beggining:

1 - Section about nested resources is missing in laravel 5.4 docs.

2 - Description of group() (routes) method is missing (only described method to use separate functions like namespace() and prefix(), not even mentioned that you can chain them).

Laravel 5.4 docs are still in beta? Am i'm the only 1 who is curious about those things or maybe i'm doing something wrong?

Should i better stick to 5.1 docs?

Thanks!

05 Jul
2 years ago

UAVova started a new conversation Nested Resources Laravel 5.4

Just saw that section about nested resources got removed from 5.4 documentation, but it still exists in laravel 5.1 docs. What is the reason? Is it ok to stick to the laravel 5.1 docs?

UAVova left a reply on Route Model Binding And Destroy Action

@bobbybouwmann I'm sorry, my bad. Thank you)

UAVova started a new conversation Route Model Binding And Destroy Action

I'm using the route model binding (implicit) in my controller and when I tried to use it for the destruction method, I've received an error

public function destroy(Post $post)
    {
        $post->detele();

        return redirect('/');
    }

Error: Call to undefined method Illuminate\Database\Query\Builder::detele()

21 Dec
2 years ago

UAVova left a reply on Ignore Blank Field On Update

@tykus_ikus Also, except only returning array without given field, but not actually excluding it from $request. So you can't use $request->all() and expect to get array without that value after executing except function, right?

UAVova left a reply on Ignore Blank Field On Update

@tykus_ikus Do you think it is best practice? I just want to be sure that i'm not reinventing the wheel, as long as i'm new to laravel

UAVova started a new conversation Ignore Blank Field On Update

I have user controller with standard CRUD structure. Users passwords stored in SHA1 values. So, when editing user i'm displaying only blank password field and when user filled it with some value -> then i will generate new password, but when it is blank, i don't want it update current password field in DB with blank value.

How can i achieve this in laravel? Probably i need some validation rule "exclude if blank" )

15 Dec
2 years ago

UAVova left a reply on Update Method Doesn't Save Data To Database

@ottoszika I just looked inside Comment model and i realized that i need some sleep))

protected $fillable = ['content, user_id, post_id'];

UAVova started a new conversation Update Method Doesn't Save Data To Database

``public function update(Request $request, $id) { $this->validate($request, [ "content" => "required", "post_id" => "required|numeric|exists:posts,id", "user_id" => "required|numeric|exists:accounts,id" ]);

    Comment::findOrFail($id)->update($request->all());

    return redirect("/admin/comments")->with("Success", "Comment has been successfully updated!");
}``

dd( Comment::findOrFail($id)->update($request->all())); Returns TRUE, but data is not saving to DB.

IDK what is wrong with markdown, so here is pastebin link - http://pastebin.com/vcJXjzvw

07 Dec
2 years ago

UAVova started a new conversation Nested Eager Loading

I want to eager load post comments and it's owner. At the same time, i want to order comments by created_at column.

To order not nested relation, i use:

$post = Post::with(['comments' => function ($query) { $query->orderBy('created_at', 'desc'); }])->find($id);

So, how can i do something like:

$post = Post::with(['comments.owner' => function ($query) { $query->orderBy('comments.created_at', 'desc'); }])->find($id);

29 Nov
2 years ago

UAVova started a new conversation Restricting Access

I have middleware, which is checking if user authenticated and it's group. I defined a routes for the group with id 3 and it is a resource posts. So, everything is fine, but for example to access show method of posts controller, you don't necessarily need to have 3 group, just to be logged in. So, from what i wrote, what is the best way to restrict access to different method of controller? What i'm thinking, is to create different route group with another middleware and use except and only methods for posts resource? Is this a good practice?

20 Nov
2 years ago

UAVova left a reply on Overwrite Vendor Trait Function

@bzbislawski Class that is using that function is inside the vendor too. So, that solution is not for my case.

@Tirke Function name is createUserProvider. I want to add

case 'sha': return $this->createShaProvider($config);

to the switch statement and also createShaProvider function.

UAVova started a new conversation Overwrite Vendor Trait Function

I need to overwrite function, that is located in: vendor\laravel\framework\src\Illuminate\Auth\CreatesUserProviders.php

How can I do that?

03 Nov
2 years ago

UAVova started a new conversation Role And Permission System

Which plugin do YOU use for role and permission management? I am looking for trusted, popular extension and for now I found entrust, but it seems to be outdated (laravel 5.3 support).

01 Nov
2 years ago

UAVova left a reply on Real Singleton?

@willvincent Thank you for the explanation.

I created singleton because i have function (fsockopen) which is executing with every request and it'll take some time to load that function. So i moved it to ajax call. But still, i wanted to make class that will hold the result of that function and return saved result, if less than 5 second passed after last request.

So, i have to store time value in file or DB, but as far as i know (i have programming experience, but not with php\laravel), i\o operations are always most expensive in terms of time. Probably the only way for me is to use DB? What is your opinion about it?

UAVova left a reply on Real Singleton?

@willvincent Ok, thank you. So each request of a page makes Laravel look at providers array, use register and boot functions in providers and etc.?

UAVova left a reply on Real Singleton?

@ohffs sad to hear that =. I was hoping that ServiceContainer holding object from server start... Turns out that each request of a page makes Laravel look at providers array, use register and boot functions in providers and etc.?

UAVova left a reply on Real Singleton?

@jusahah87 it is ok, but what is the point of singleton than? I thought that laravel creates class with the first call and just returning created object.. Isn't it a singleton?

UAVova started a new conversation Real Singleton?

I have class:

<?php

namespace App\Services;

class ServerStatus
{
    public $status = 1;

    public function get()
    {
        $this->status++;
        return $this->status;
    }
}

and in provider:

  public function register()
    {
        $this->app->singleton('ServerStatus', function () {
            return new ServerStatus;
        });
    }

For test i'm using this:

Route::get('/', function() {
dd($this->app['ServerStatus']->get());
});

And it is always printing out 2 when i'm refreshing page. So, why should it always print 2 if it is singleton?

UAVova left a reply on Tutorial Is Wrong?

@zachleigh Just tried to remove app::bind and leave Bar class in the file - and it is working as expected. It is also explained in that tutorial as Reflection.

UAVova left a reply on Tutorial Is Wrong?

@zachleigh That is why i'm asking. Also, if i'm doing something like:

class Bar {
  protected $val;

  public function __constructor()
  {
      $this->val = 1;
  }

  public function get()
  {
      return $this->val += 1;
  }
}

App::singleton('Bar', function() {
  return new Bar;
});

Route::get('/', function (Bar $br) {
    dd($br->get());
});

I always get 1 in output. So, App::singleton is not working in this case.

UAVova left a reply on Tutorial Is Wrong?

@zachleigh And if you remove App:bind, it'll use reflection and resolve class as well. Right?

UAVova left a reply on Tutorial Is Wrong?

@zachleigh Ok, so why do we need App::bind method, if we can just go with use Path\To\Class ?

UAVova left a reply on Tutorial Is Wrong?

@jusahah87 see the tutorial. Everything like in that tutorial.

UAVova started a new conversation Tutorial Is Wrong?

According to the tutorial - Laravel 5 Fundamentals: The Service Container This code must work:

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/

App::bind('Bar', function() {
  dd('fetching');
});

// Ajax url for getting server status
Route::get('ajax/server-status', function (Bar $stat) {
  dd($stat);
});//'[email protected]');

But when i visit localhost/ajax/server-status - i got

ReflectionException in Route.php line 339:
Class Bar does not exist

UAVova left a reply on Service Container - Class Does Not Exist

@vpower So what is the point to use Service Container if i directly include namespace? It'll use reflection.

UAVova left a reply on Service Container - Class Does Not Exist

And I think that fact that I get instance when inspecting with dd() function inside register() method is a guarantee that namespace, path and name are right.

UAVova left a reply on Service Container - Class Does Not Exist

@maitrefrantz right after beginning of '''register''' function. Path to the file: app/Services/ServerStatus.php

31 Oct
2 years ago

UAVova left a reply on Service Container - Class Does Not Exist

@maitrefrantz it is defined correctly, i tested it with: dd(new ServerStatus()) and it returns new class instance.

UAVova started a new conversation Service Container - Class Does Not Exist

I've created service (class):

<?php

namespace App\Services;

class ServerStatus
{
    protected $status = 1;

    public function get()
    {
        $this->status = $this->status + 1;
        return $this->status;
    }
}

and provider

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Services\ServerStatus;

class ServerStatusServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('ServerStatus', function ($app) {
            return new ServerStatus();
        });
    }
}

And when i try to do something like this in controller:

  public function serverStatus(ServerStatus $stat)
    {
        $status = $stat->get();
    }

I got:

ReflectionException in Route.php line 339:
Class App\Http\Controllers\ServerStatus does not exist

UAVova left a reply on Ajax Call Hangs Server

@Snapey Just came here to say that 1 min ago i tested it on apache2 and it is working fine) Thank you! I was not completely understanding what is behind "php artisan serve" command.

UAVova left a reply on Ajax Call Hangs Server

@jimmck As long as i'm not using ReactPHP, just plain laravel with built-in php server - probably not.

UAVova left a reply on Ajax Call Hangs Server

@jimmck Where can i find it out?

UAVova left a reply on Ajax Call Hangs Server

Guys, i need your help. Laravel can't be that slow. Should i use some other php server (rather than php artisan serve) to gain performance or multithreading in production? Because it is not normal for php framework to wait until controller finishes executing function and only then server will respond to other requests. I just can't believe that it is like that... in terms of performance

UAVova started a new conversation Ajax Call Hangs Server

I have ajax call which is executing after DOM is loaded:

$(document).ready(function() {
    if ($('#block').length > 0) {
      $.ajax({
        type: 'GET',
        url: location + 'ajax/status',
        success: function(msg) {
          $('#block').append(msg);
        }
      });
    }
});

It is handeled by function:

function ajax() 
{
    $status[] = @fsockopen('example.com', 80, $errNum, $errMsg, 1);
    $status[] = @fsockopen('example.com', 80, $errNum, $errMsg, 1);
    $status[] = @fsockopen('example.com', 80, $errNum, $errMsg, 1);
    return view('ajax.servers', compact('status'));
}

So, when i visit INDEX page - DOM is loaded, ajax call started and i CAN'T visit any page of my site until AJAX function is executing. Server is just waiting until function is executing and it is definetely not normal. Earlier i was writing same thing on RoR and it worked just fine. How can i deal with that? Laravel is one threaded? How is that possible?