jsrosas

jsrosas

Member Since 3 Years Ago

Tamarac, FL

Experience Points 11,310
Experience Level 3

3,690 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 96
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.

11 Jan
2 years ago

jsrosas left a reply on HasMany With Chained Where() Returning Empty.

Thanks @Snapey I just wasn't sure if there was limit to chained where().

jsrosas started a new conversation HasMany With Chained Where() Returning Empty.

Hey all, how are you doing. I have a has many relation with 2 chained where clauses, when I add a third it always returns empty, even though it should find a match. Is there a limit to where clauses that can be chained?

public function tudisputes(){
        return $this->hasMany('App\Dispute', 'account_number', 'account_number_tu')->where('bureau', 'TransUnion')
                    ->where('client_id', $this->client_id);
    }

returns what its supposed to return.

public function tudisputes(){
        return $this->hasMany('App\Dispute', 'account_number', 'account_number_tu')->where('bureau', 'TransUnion')
                    ->where('date_open', $this->date_open_tu)
                    ->where('client_id', $this->client_id);
    }

Returns nothing. I am positive it should find a match in my data.

08 Nov
2 years ago

jsrosas left a reply on Lazy Load Custom Function From Model

If I call with('disputes') I get:

Method addEagerConstraints does not exist. This function is not a regular relationship, its a custom query. How can I merge 2 collections?

07 Nov
2 years ago

jsrosas left a reply on Lazy Load Custom Function From Model

How can I fetch the data in the controller and append to each model in the collection? I cant change the design of the database.

jsrosas left a reply on Lazy Load Custom Function From Model

@Snapey Hi snapey, the database design doesn't follow the correct pattern for me to do a belongs to or hasmany. I have to do a custom query to fetch the correct records. @willvincent I thought it would be lazy loaded because I wanted to call the function inside the model after the model has been fetched. Otherwise how can I have the function eager loaded with the Model? I welcome any suggestions to improve this.

jsrosas started a new conversation Lazy Load Custom Function From Model

Hi All; I have a custom function in a model which does a query to another table to fetch some records.

public function disputes($user_id){
        return Dispute::where('account_name', $this->account_tu)->where('account_number', $this->account_number_tu)->orWhere('account_name', $this->account_ex)->where('account_number', $this->account_number_ex)->where('user_id', $this->user_id)->get();                
    }

Is there a way to lazy load and append to the model collection from the controller? Right now the function is called from blade and it slows down the script. Thank you in advance.

02 Nov
2 years ago

jsrosas left a reply on Set A Variable Name Out Of 2 Other Variables Inside A For Loop

Hi @tomi That just outputs from 1 to 24 but its not fetching the information. I guess it just disregards the $acc->history()[1]->month. I am not sure if its important but history() is a function declared in the model of accounts which lets me do a custom query to fetch data from a separate table. But it returns a collection. I am able to output the data if I go one by one {{$acc->history()[1]->month1}} and {{$acc->history()[1]->month2}} but I'd like to loop it.

jsrosas started a new conversation Set A Variable Name Out Of 2 Other Variables Inside A For Loop

Hi all, I have a database not designed by me which has some values as month1, month2, month3 etc etc until month24. I need to display each value and I am looking for a quicker way other than manually doing 24 HTML lines. Because for each of this values echoing in Blade I have to do if, ifelse checks. I was hoping I could do a for loop and just concatenate the variable name with the index of the for loop to the the month1 until month24

@for($i =1; $i< 25; $i++)
              @php
               echo $acc->history()[1]->month{{$i}};
              @endphp
 @endfor

And I keep getting Parse error: syntax error, unexpected '?'. I tried doing:

@{{$acc->history()[1]->month.$i}}

But that just simply echoes the desired variable name as a string. Any ideas how to solve this? Or a better way to iterate through the fields?

30 Aug
2 years ago

jsrosas left a reply on Centos7->Nginx->Laravel5.2

Any help?

jsrosas left a reply on Centos7->Nginx->Laravel5.2

P.S if I do php artisan optimize I loose my test route and all routes display 500. The only way I get back my test route is by doing php artisan cache:clear. Hope that gives you a clue and you can help me solve this issue. Thank you.

jsrosas started a new conversation Centos7->Nginx->Laravel5.2

Hi all, I have an issue I cant figure out. I have CentOs7 installed with MariaDB, PHP5.6, Nginx 1.6.3. Nginx conf file looks like this:

server {
    listen       80;
    server_name  192.168.1.60;

    # Document Roo
    root   /usr/share/nginx/cybertrack/public;
    # Index
    index  index.php index.html index.htm;

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        fastcgi_max_temp_file_size 0;
        fastcgi_buffer_size 4K;
        fastcgi_buffers 64 4k;

        include        fastcgi_params;
    }
}

I have done all this commands mentioned in another post

sudo chown www-data:deploy <laravel_directory>/storage/logs/laravel.log
sudo chown root:deploy -h <laravel_directory>/.env
sudo chown www-data:deploy -R <laravel_directory>/bootstrap

php artisan key:generate
php artisan cache:clear
php artisan clear-compiled

But I always get 500 when I try the root index. I created a new route which just returns "ok"; and I see it working returning ok on the browser. But if I change that same new route to return a view('welcome') I get 500. The entire application folder is owned by nginx user and has drwxrwxr-x. permission. I also checked the resources folder just in case since the routes work but no view, and has the same permissions. I did all my chown's and chmod's with -R. What else can be wrong?

18 Aug
2 years ago

jsrosas left a reply on Array Casting Of Serialized Returns Null

So when I initially save the information I can to toJson()? that will store in MySQL?

jsrosas left a reply on Array Casting Of Serialized Returns Null

Currently I get

Missing argument 1 for App\Order::getSkuAttribute() Even though the field is called sku on DB.

jsrosas left a reply on Array Casting Of Serialized Returns Null

Thank you @SaeedPrez How do I call this later on the controller? I'd like to do:

$orders = Order::with('sku')->get();

So I can get an array within every $order in $orders

jsrosas started a new conversation Array Casting Of Serialized Returns Null

Hi all, I have an issue with casting a serialized 'sku' attribute to array. In my database its saved as a:2:{i:0;s:7:"sophia1";i:1;s:3:"dog";} On my order I am casting sku to array

protected $casts = [
        'sku' => 'array',
    ];

Then I retrieve a single order on my controller and do dd($order->sku); This returns null. But if I remove the cast and manually do unserialize($order->sku) I get my desired array. I cannot just pass unserialized array to the view as it gives me a htmlentities() error.

02 Aug
2 years ago

jsrosas left a reply on Getting Collection From Lazy Loading But And Showing Attributes On Blade.php

In the end I did my query like this

$clientOrders=Order::whereIn('user_id',  $this->user->pluck('id'))->get();
         return $clientOrders;

This is just returning a collection of Orders with the user_id from the User's that belong to the Member class. I tried hasmanythrough but it returned empty. The query mentioned above may be intensive but right now its my best solution.

Member::hasManyThrough('App\Order', 'App\User');  
01 Aug
2 years ago

jsrosas left a reply on Getting Collection From Lazy Loading But And Showing Attributes On Blade.php

ok thank you both @Snapey and @d3xt3r I will try the hasthrough first, and then nesting the for each in blade.

jsrosas left a reply on Getting Collection From Lazy Loading But And Showing Attributes On Blade.php

@Snapey the id is the order id the user_id isnthe id of the user they belong to, stripe_id isnthe order number from stripe.

jsrosas left a reply on Getting Collection From Lazy Loading But And Showing Attributes On Blade.php

@Snapey thanks for the suggestion, I am returning $clientOrder which is called form the Member class like this:

 public function clientOrders(){
        $clientOrders=$this->user->load('order');
        return $clientOrders;
    }

jsrosas left a reply on Getting Collection From Lazy Loading But And Showing Attributes On Blade.php

Member class has

public function user(){
        return $this->hasMany('App\User');
    }

User class has

public function member(){
        return $this->belongsTo('App\Member');
    }
public function order(){
        return $this->hasMany('App\Order');
    }

Order class has

public function user(){
        return $this->belongsTo('App\User');
    }

When I dd($clientOrders), I get a collection of all the Users that belong to the Member, and each user has a relationtion key with the Order. I could paste the whole collection but it would be difficult to read.

jsrosas left a reply on Getting Collection From Lazy Loading But And Showing Attributes On Blade.php

Thats the thing, If I just do on blade {{$clientOrder->order}} I get the following collection of 4 orders. Each on in its own But I cannot access {{$clientOrder->order->id}}

[{"id":12,"user_id":83,"stripe_id":"or_18djYKKR0gYurAdXUWb1N0kr","email":"[email protected]","amount":29700,"sku":"sophia1","product":"Sophia1","quantity":3,"address_1":"123 test","address_2":null,"city":"951","zip":"65432","country":"United States","status":"created","created_at":"2016-08-01 12:48:37","updated_at":"2016-08-01 12:48:37"}]
[{"id":13,"user_id":88,"stripe_id":"or_18dlr1KR0gYurAdX0j30ZkV2","email":"[email protected]","amount":9900,"sku":"sophia1","product":"Sophia1","quantity":1,"address_1":"12345 st","address_2":null,"city":"San Jose","zip":"95145","country":"United States","status":"created","created_at":"2016-08-01 15:16:05","updated_at":"2016-08-01 15:16:05"}]
[{"id":14,"user_id":91,"stripe_id":"or_18dnW5KR0gYurAdX3nv626mV","email":"[email protected]","amount":9900,"sku":"sophia1","product":"Sophia1","quantity":1,"address_1":"123 jj bb","address_2":null,"city":"Schenectady","zip":"12345","country":"United States","status":"created","created_at":"2016-08-01 17:04:23","updated_at":"2016-08-01 17:04:23"},{"id":15,"user_id":91,"stripe_id":"or_18dnW5KR0gYurAdX3nv626mV","email":"[email protected]","amount":9900,"sku":"sophia1","product":"Sophia1","quantity":1,"address_1":"123 jj bb","address_2":null,"city":"Schenectady","zip":"12345","country":"United States","status":"created","created_at":"2016-08-01 17:05:31","updated_at":"2016-08-01 17:05:31"}]

jsrosas left a reply on Getting Collection From Lazy Loading But And Showing Attributes On Blade.php

I can just loop through one client because I have many clients and each one will have many orders. I need a collection that will get me all of them. I am already getting that result but I cannot access each key of each collection.

jsrosas left a reply on Getting Collection From Lazy Loading But And Showing Attributes On Blade.php

In my app one User can have many oders. So the model of User has return $this->hasMany('App\Order');

jsrosas started a new conversation Getting Collection From Lazy Loading But And Showing Attributes On Blade.php

Hi All, I have an issue I cant figure out. I am lazy loading a relation like this. a Member has many Users, User has many Orders. So I am calling from within the model.

public function clientOrders(){
        $clientOrders=$this->user->load('order');
        return $clientOrders;
    }

Then I pass it to the view through the controller with compact('clientOrders');

   <tbody>
                           @foreach ($clientOrders as $client)
                           <td>{{$client->order->stripe_id}}</td>
            @endforeach 
 </tbody>                           

But I get

Undefined property: Illuminate\Database\Eloquent\Collection::$stripe_id Even though when I do {{$client->order}} I get the full list of attributes.

[{"id":12,"user_id":83,"stripe_id":"or_18djYKKR0gYurAdXUWb1N0kr","email":"[email protected]","amount":29700,"sku":"sophia1","product":"Sophia1","quantity":3,"address_1":"123 test","address_2":null,"city":"951","zip":"65432","country":"United States","status":"created","created_at":"2016-08-01 12:48:37","updated_at":"2016-08-01 12:48:37"}]
22 Jul
2 years ago

jsrosas started a new conversation DD And Return Not Giving Me The Same Results

Hi All, I am trying to retrieve the id of the subscription of a User in my controller and return it to the view. So my controller code looks like this:

public function stripe_info(){
        $stripe_info = Stripe::customers()->find($this->stripe_id);
        $subscription = $stripe_info['subscriptions']['data']['0']['plan']['id'];
        dd($subscription);
    }

I am using Cartalyst's Laravel library because it gives me more options. So when I DD the result It works fine, but when I return $subscription I get :

Undefined offset: 0 (View: C:\inetpub\wwwroot\cybertrack\resources\views\admin\membershow.blade.php) But DD returns to view the actual value I am looking for, of course it breaks the rest of the page. Why does the result change when I return?

12 Jul
3 years ago

jsrosas left a reply on Adding Foreign Keys After Creating All Tables.

Thanks @bmcconn, that was one issue, but I still get the error:

SQLSTATE[HY000]: General error: 1005 Can't create table 'localtest.#sql-62c_43cc'

Only on the members table. Is that a temporary table it's trying to create for some reason or why is trying to create a table called : sql-62c_43cc? Thanks so much, I may just resort to restarting the mySQL server like suggested before would that be the best fix?

jsrosas left a reply on Adding Foreign Keys After Creating All Tables.

That sounds like a hack but it could work, unless there is a proper way to do it.

jsrosas left a reply on Adding Foreign Keys After Creating All Tables.

Is there a better way to declare foreign constrains so that I don't get errors regarding the order in which they were created? That's the main reason why I'm trying this approach.

jsrosas started a new conversation Adding Foreign Keys After Creating All Tables.

Hiya all, I created some tables and now I would like to add my key constrains after all tables have been created, so I am doing a new migration file with instructions for all foreign keys to be created, even though its running after all the tables have been created I get:

SQLSTATE[HY000]: General error: 1005 Can't create table 'localtest.#sql-62c_41c6' (errno: 150) (SQL: alter table >member_payments add constraint member_payments_member_id_foreign foreign key (member_id) references >members (id))

The migration file looks like this:

public function up()
   {
       Schema::table('users', function (Blueprint $table){
           $table->foreign('member_id')->references('id')->on('members');
       });
       Schema::table('member_payments', function (Blueprint $table){
           $table->foreign('member_id')->references('id')->on('members');
       });
   }

   /**
    * Reverse the migrations.
    *
    * @return void
    */
   public function down()
   {
       Schema::table('users', function (Blueprint $table) {
           $table->dropForeign(['member_id']);
       });
       Schema::table('member_payments', function (Blueprint $table) {
           $table->dropForeign(['member_id']);
       });
   }

Any ideas why its generating this error? thank you in advance.

11 Jul
3 years ago

jsrosas left a reply on Laravel Cashier Swap In Bulk

This is supposed to be an option for an admin to be able to lower all the users subscriptions. So I'm making a controller that at this point will loop through each member and swap their subscriptions. I wonder if there is a better way.

jsrosas left a reply on Laravel Cashier Swap In Bulk

It has to be done with the GUI or blade view. But then the only function to update a plan is with the swap function? No alternatives correct?

jsrosas started a new conversation Laravel Cashier Swap In Bulk

Good morning all, hope you weekend was good. I would like to know the best way to perform a bulk swap for subscriptions using Laravel Cashier. My thought is doing a for each User running the swap function from cashier. That would be pretty intense on the server I am wondering if there is a more optimized way of doing it instead of going by each user and changing it.

29 Jun
3 years ago

jsrosas left a reply on ForEach On Collection From Model Returns Empty

Hi @bobbybouwmann I just ended up using {{number_format($member->invested(),2)}} on my blade template. Seems to work. Thank you.

jsrosas left a reply on ForEach On Collection From Model Returns Empty

And here I am trying to complicate myself by doing a foreach, I still don't understand why it wont let me Iterate through each but this solves my problem thank you @bobbybouwmann

jsrosas started a new conversation ForEach On Collection From Model Returns Empty

Hiya all, once again with probably a newbie question lol. I'd appreciate your help. I have some users that are making payments into Stripe and I am storing the amounts they are paying in a table. I have a relationship of User::hasmany, and UserPaymphpent::belongsto. So when I have

    public function charges(){
        return $this->hasMany('App\UserPayment');
    }

I get a collection of payments done by that Use. Now I need to iterate through each payment and sum up all the amounts they payed. When I just simply return the collection I get on blade the following:

[{"id":1,"member_id":"44","stripe_id":"cus_00000000000000","email":"[email protected]","amount":50000,"amount_decimal":0,"amount_refunded":0,"invoice_number":null,"date_created":1326853478,"created_at":"2016-06-28 20:12:35","updated_at":"2016-06-28 20:12:35"},{"id":2,"member_id":"44","stripe_id":"cus_00000000000000","email":"[email protected]","amount":50000,"amount_decimal":0,"amount_refunded":0,"invoice_number":null,"date_created":1326853478,"created_at":"2016-06-28 20:12:35","updated_at":"2016-06-28 20:12:35"},{"id":3,"member_id":"44","stripe_id":"cus_8iuCeLKHZGxWQD","email":"[email protected]","amount":50000,"amount_decimal":0,"amount_refunded":0,"invoice_number":null,"date_created":1467144078,"created_at":"2016-06-28 21:10:19","updated_at":"2016-06-28 21:10:19"}]

So I thought I could do foreach and just += each $payment->amount. But the for each is not going through them. Just returns blank, even If I just simply do inside the foreach($payments as $pay){echo "one payment";} I get blank. So I tried json_decode on the $payments collection and I get:

json_decode() expects parameter 1 to be string, object given How can I iterate through each payment and sum up the amounts? Thank you in advance.

27 Jun
3 years ago

jsrosas left a reply on Trying To Get Count Of A Model Must Return An Object Of Type

I may set a counter field on the members instead and just retrieve that, I am still pretty early on the project. Plus I am clueless about joins yet. I'll read into it. Thank you all for your help.

jsrosas left a reply on Trying To Get Count Of A Model Must Return An Object Of Type

@Snapey Indeed this is a bit heavy any other solution I am all ears. I expect to have at least 5000 of this members so it will be a crazy query.

jsrosas left a reply on Trying To Get Count Of A Model Must Return An Object Of Type

@willvincent Yes that was a typo I hand typed the $members as $member. But what fixed it is

{{ $member->refer() }}

Thank you.

jsrosas left a reply on Trying To Get Count Of A Model Must Return An Object Of Type

Hi @tomo_pongrac I need to get the count for of all the members that have the id of the member in their vendor field from the db. So in model I am doing a function that provides me that count.

public function refer(){
        $referCount = Member::where('referer_id', $this->vendorname)->count();
        return $referCount;
    }

Now for each member I need to be able to pass that count to blade. So I am trying to call in blade $member->refer. But it gives me an error: Relationship method must return an object of type

jsrosas started a new conversation Trying To Get Count Of A Model Must Return An Object Of Type

Hi All, I am trying to get a count of all the model with a specific parameter. The model name is Member, inside the model I am declaring this function to get a count of all the other members that have a field that matches the id of the current Member.

public function refer(){
        $referCount = Member::where('referer_id', $this->vendorname)->count();
        return $referCount;
    }

Then in blade I am trying to call it by using $member->refer in a @foreach loop. I get

Relationship method must return an object of type Does anyone have any ideas? If I do a dd($referCount) I get the desired value. Is there another way to get this result? This is for a dashboard and I'll need to do this kind of queries. So it will be

@foreach($members as $members)
<td>{{$member->first_name}} {{$member->first_name}}</td>
                                <td>{{$member->email}}</td>
                                <td>{{$member->refer}}</td>
                <td>{{$member->products_sold}}</td>

And so on I am just looking for a simpler way of doing this queries and being able to call them in blade in for a for each loop. Thank you in advance.

24 Jun
3 years ago

jsrosas left a reply on Set New Instance Of Model In Controller

Thanks @clay I kept trying to create a new instance of the class.

jsrosas left a reply on Set New Instance Of Model In Controller

When I just do a Member::where it gives me the information of the edited Member not the Member I am trying to find to get the data from.

jsrosas left a reply on Set New Instance Of Model In Controller

Yes the namespace is correct, like I mentioned it only happens when I try to set a new Model so that the new Model can hold the information of the Model I am trying to fetch. In other words I need to have access to the one Model being edited and a Model being fetched from the database which holds a value that needs to be set on the Model being edited. I need 2 instances of the same model in my controller. How do I set a new instance?

jsrosas started a new conversation Set New Instance Of Model In Controller

Hiya all, Thanks in advance for any help you can provide. I have a controller which sets some fields for a model Member. Now this model Member is a customer that will be referred by other Member. So the User has a field where they can select the name of the Member that referred them. In the controller I have to find that Member(referrer) and assign its ID to the referrer_id field of the new Member. The problem is that when I go and fetch the referrer Member it holds the information from the new Member. How do I create a new instance of the Member model in my controller so that I can do my query? I am trying:

$refer = new Member::where('vendorname', $vendorname)->firstOrFail();

But I get:

Class App\Http\Controllers\MemberProfileController does not exist

It does though lol. Not sure why it throws this error. Either way when I remove the new from my query and I dd($refer), It gives me the information of the new Model being edited. Again thanks in advance.

22 Jun
3 years ago

jsrosas left a reply on Use Stripe\Customer As StripeCustomer In Controller Throws Error

Im beginning to think maybe require() will be easier.

jsrosas left a reply on Use Stripe\Customer As StripeCustomer In Controller Throws Error

Yes it returns the id of one of my test customers "cus_8gQFFsLjewyhiW"

jsrosas left a reply on Use Stripe\Customer As StripeCustomer In Controller Throws Error

Well I am declaring the Stripe\Customer like this:

use Stripe\Customer as StripeCustomer; And Im using it in my function like this: $stripeCustomer = StripeCustomer::retrieve($admin->stripe_id);

I saw on the Billable calls that Stripe is being called like that :

use Stripe\Customer as StripeCustomer;