sorcjc

sorcjc

Hire Me

Member Since 3 Years Ago

Experience Points 2,995
Experience
Level
Lessons Completed 16
Lessons
Completed
Best Reply Awards 0
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.

03 Jan
11 months ago

sorcjc left a reply on Call To Undefined Method App\Services\Storage::disk()

And what was your solution?

02 Jan
11 months ago

sorcjc left a reply on Why Use Service Providers? Any Examples?

Hi. Sorry for post in this old thread. But my question is related to the same.

As I understand, Service Providers are useful because:

  • they allow us creating new instances than require some configuration
  • we can use a contract (or interface) and change the implementation of the service if needed

A service provider is a class that can register bindings in the service container, and provide services in this way.

However, if I have a service with no dependencies (a simple class instantiation), I don't need service providers. Is it?

I have a class CvHandler that I want to use from different locations. So I was creating a service provider, to be able to use dependency injection.

However, I have not added $this->app->bind(CvHandler::class); to the register method, and the dependency injection is available for this class (it means it is not necessary to use providers for classes with no dependencies, right?).

29 Dec
11 months ago

sorcjc left a reply on [L5.5]sometimes Db Connections Refused

Hi @lawlietee

Did you find a solution for this strange behavior?

13 Oct
1 year ago

sorcjc left a reply on What Is The Best Setup For A Subscription System?

2 years later can you share with us some thoughts about how to implement a subscription system? :)

01 Oct
1 year ago

sorcjc left a reply on Laravel Pagination Returns Links In Http And Not Https

@ernest-okot Thank you!

Now I am using ->setPath('/');.

And it works (the links are generated over https).

11 Sep
1 year ago

sorcjc left a reply on Where The Artisan Commands Are Declared?

Thank you @Jaytee

In the ServeCommand class I see that php artisan serve is equivalent to php -S 127.0.0.1:8000 C:/wamp/www/my-project/server.php.

When I run this command, the server is initiated at 127.0.0.1:8000, however the assets doesn't load.

I mean, the styles and scripts gives a 404 error. For example 127.0.0.1:8000/css/styles.css doesn't load, even when it is located in the public folder and works well with php artisan serve.

Do you know why? :(

10 Sep
1 year ago

sorcjc left a reply on Where The Artisan Commands Are Declared?

@jlrdw I have seen the docs.

I want to see the definitions of the default commands.

sorcjc started a new conversation Where The Artisan Commands Are Declared?

Hi. In what files of the vendor folder are the commands defined? I want to know more about the framework, but I can't find those definitions. Thank you in advance.

29 May
1 year ago

sorcjc left a reply on Link A Laravel App With Two Different Subdomains

@Thyrosis Thank you for your help.

Finally I have associated both subdomains with the same droplet, and manage the routes in the same Laravel app.

I didn't know than that was possible.

The routes in Laravel are awesome.

26 May
1 year ago

sorcjc left a reply on How Can I Get Domain Name Used To Visit An App?

@ashitvora How did you get the domain finally?

Thank you.

23 May
1 year ago

sorcjc started a new conversation Link A Laravel App With Two Different Subdomains

Please, let me describe my situation:

  • Initially I had a blog on my domain: myweb.com (powered by Jekyll)
  • After that I have created a Laravel app in a Digital Ocean droplet, and associate it with a subdomain: tutorials.myweb.com
  • Now I want to create a new functionality on my Laravel app that allow users to create galleries.

The problem is, the URL for the galleries will be: tutorials.myweb.com/galleries But the galleries are not associated with the tutorials directly.

I want to use galleries.myweb.com, but associate this subdomian with tutorials.myweb.com/galleries, because I want to use the same Laravel app (to share the same users).

Is it possible? How I can achieve it? Please give me ideas.

Thank you in advance.

14 May
1 year ago

sorcjc left a reply on Modify The Header And Footer In Mail Markdown Mails

@poldixd Why we can't edit the message.blade.php file in vendor/mail/markdown?

I have edited that file, but there aren't changes in the emails.

13 May
1 year ago

sorcjc started a new conversation Question About The RegistersUsers Trait

In the RegistersUsers trait, we have:

public function register(Request $request)
{
    $this->validator($request->all())->validate();

    event(new Registered($user = $this->create($request->all())));

    $this->guard()->login($user);

    return $this->registered($request, $user)
                    ?: redirect($this->redirectPath());
}

My doubt is about the registered method. Because it is defined as follows:

protected function registered(Request $request, $user)
{
    //
}

Why it is blank? It suggest us to define this method? I want to register via ajax. Should I check in the registered method if it is an ajax request and return a json?

Thank you in advance.

07 May
1 year ago

sorcjc left a reply on Using Default Laravel 5 Auth Controller - Logout

@Snapey That is possible? I mean, the login request always require a csrf token.

26 Apr
1 year ago

sorcjc left a reply on Code After Middleware

@clay But how I can instantiate the $user variable in the middleware and use it in the controller? It is a different scope, I guess.

@jbloomstrom No. I am sure that the session is always set, and it works. But when the session of the user ends, I get the error. Are you sure that the code after the middleware in constructor is executed after the middleware validation?

Thank you both, for your help.

sorcjc started a new conversation Code After Middleware

Hi. I want to execute some code after the middleware (when the validation is OK), in the constructor of my class.

In summary, I have the next:

class QuoteController extends Controller
{
    private $user;

    public function __construct()
    {
        $this->middleware('auth');

        // Code:
        if (auth()->user()->is_admin)
            $this->user = User::find(session('client_id'));
        else
            $this->user = auth()->user();
    }
}

I have an attribute named $user to access to the authenticated user (for clients), or in some cases, to the selected user (the administrators can access to the panel of the users, using a session variable).

It works great. But when the session comes to end, I get the next error message:

Trying to get property of non-object

It happens because auth()->user() is null. I can use auth()->check() to avoid it. But I prefer to execute the code after the middleware passes.

How I can achive that? Please give me some ideas.

Thank you in advance!

28 Feb
1 year ago

sorcjc left a reply on Add Watermark/stamp To PDF With Preview

Hi. Did you find some solution for the pdf stamping?

07 Feb
1 year ago

sorcjc left a reply on How To Auto Post On Facebook Using Laravel 5.1

@moharrum I have used this package to perform some queries to the Facebook Graph API. But, I don't know how to post using it.

Please, do you have some example?

Probably @omontes has used a different package.

04 Feb
1 year ago

sorcjc left a reply on Laravel Mix ERROR ( LARAVEL 5.4.5)

I am getting Error: Cannot find module 'C:\wamp\www\billetero\node_modules\cross-env\bin\cross-env.js' :/

24 Jan
1 year ago
21 Jan
1 year ago

sorcjc left a reply on Validator - Ignoring Field If Value Is 0 For Exists Rule.

The sometimes rule checks if the field exists in the proper table, but only if its value is other than empty/null.

0 (zero) is evaluted in Laravel 5.3

15 Jan
1 year ago

sorcjc started a new conversation Array Validation

I have the next lines (simplified):

        $rules = [
            'name' => 'required|min:4',
            'services.*' => 'exists:services,name'
        ];
        $messages = [
            'name.required' => 'Debes ingresar el nombre del proyecto.',
            'name.min' => 'El nombre del proyecto debe constar de al menos 4 caracteres.',
            'services.*' => 'El servicio indicado en :attribute no existe en la base de datos.'
        ];
        $this->validate($request, $rules, $messages);

Using * I can apply the validation to each item in services. But I want to show a custom error message, and say to the user the position or at least, the name of the incorrect service name.

Using :attribute the error message shows services.1 when the 2nd service name fails. I can understand it, but not the user. How I can put the position in the message?

I have tried with: :position, :i, :value, but doesn't work.

Please help me. Thank you.

08 Jan
1 year ago

sorcjc left a reply on Using Middleware In Constructor

@LozovoyV Thank you. But, I want to share the variable in one specific controller using an attribute. And it works, but the middleware is ingnored :/

sorcjc started a new conversation Using Middleware In Constructor

Hi. I have the next code in my ProjectController:

    public function __construct()
    {
        $this->middleware('auth');

        // Projects associated with
        if (auth()->user()->is_admin)
            $this->user = User::find(session('client_id'));
        else
            $this->user = auth()->user();
    }

I have a user private attribute.

When a regular user is authenticated, that user will manage his/her projects.

But if the authenticated user is an admin, and have selected a specific user, he/she can modify the projects of the selected user.

It works well, but the middleware seems ignored. Because I have got this error: Trying to get property of non-object In the if line.

Thank you in advance.

01 Jan
1 year ago

sorcjc started a new conversation Laravel + Jekyll

Hi. I have a blog powered by Jekyll, and it is hosted by Github pages.

It works well, but I want to add backend features. For that I plan to use a Digital Ocean droplet.

But, I want to still make posts using the Jekyll markdown and don't lose the generated permalinks.

Should I develop a simple blog in Laravel and migrate all my posts? Laravel uses blade and Jekyll also have layouts but uses another syntax.

Please give me some ideas about how to use Laravel and Jekyll.

Thank you in advance.

16 Dec
2 years ago

sorcjc left a reply on NoSQL In Laravel

There is a easy way to store JSON objects in a table field using Laravel?

15 Dec
2 years ago

sorcjc left a reply on How To Apply HTTPS To The Helpers Asset And Url

I finally found a solution:

<?php
namespace App\Providers;

use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot(UrlGenerator $url)
{
  if(env('APP_ENV') !== 'local')
  {
    $url->forceSchema('https');
  }
}

Thanks to @jekinney for post this solution in https://laracasts.com/discuss/channels/laravel/mixed-content-issue-content-must-be-served-as-https

sorcjc left a reply on How To Apply HTTPS To The Helpers Asset And Url

Thank you both for your help.

@tyfc I have changed the APP_URL in my .env, but I am still getting the warnings:

Mixed Content: The page at 'https://mysite.com/' was loaded over HTTPS, but requested an insecure script 'http://mysite.com/assets/js/main.js'. This request has been blocked; the content must be served over HTTPS.

@craigpaul In this case I want to override the helpers, since I have used the helpers in a lot of pages. Should I use the next?

function asset($path)
{
  return asset($path, env('REDIRECT_HTTPS'));
}

sorcjc started a new conversation How To Apply HTTPS To The Helpers Asset And Url

Hi. I am using L5.2 and after I added the HTTPS protocol using CloudFlare, I have problems with the assets path and the links.

Before I was using the helpers as follows: {{ asset('js/my_script.js') }} {{ asset('css/my_styles.css') }}

But the helpers generate a full path with HTTP instead of HTTPS. To correct that I add a second parameter (TRUE to use a secure path). Since I work locally I also need to set the 2nd parameter as FALSE and just use TRUE in producto.

To achive that I have the following: {{ asset('js/my_script.js', env('REDIRECT_HTTPS'))) }} {{ asset('css/my_styles.css', env('REDIRECT_HTTPS'))) }} And that works. But, I would have to modify all my blades.

There is a more simple way to do it? Or how I can override the helpers? I want to set a default value to the 2nd parameter (my env variable).

Thanks in advance.

09 Dec
2 years ago

sorcjc left a reply on Set X-FRAME-OPTIONSon Laravel 5.0

@thisisyusuf Did you solve this?

I am trying to show a laravel page into a facebook page tab, but it doesn't allow fb to embed apparently.

22 Sep
2 years ago

sorcjc left a reply on Submitting Form In Vue.js With Ajax

@bestmomo Do you have som example using vue and blade? I can't use @submit neither v-on:submit="addElement" Thanks.

21 Sep
2 years ago

sorcjc left a reply on (how To) CRUD With Vue Ajax And Laravel

@mesqueeb Two months later, you have used vue with laravel? Maybe you have some example to share (:

27 Aug
2 years ago

sorcjc left a reply on How To Solve CURL Error 60: SSL Certificate In Laravel 5 While Facebook Authentication

I have download the caert.pem file and save it in C:\wamp\bin\php\php5.5.12, with the proper extension. Next I modified and uncomment the next line:

curl.cainfo = "c:/wamp/bin/php/php5.5.12/cacert.pem"

But it still doesn't work. I get the same error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

17 Aug
2 years ago

sorcjc left a reply on About JSON Errors Response

MessageBag has errors and each error may contain a list of values, but in what cases? I always get arrays with just one string. Thanks.

sorcjc started a new conversation About JSON Errors Response

Hi. I am using the following code:

    $validator = Validator::make($request->all(), [
            'category_id' => 'required|exists:categories,id',
            'title' => 'required|min:5|max:255',
            'limit' => 'required|integer|min:2|max:25'
        ]);

        if ($validator->fails())
        {
            return response()->json([
                'success' => false,
                'errors' => $validator->getMessageBag()->toArray()
            ], 400); // HTTP code for an invalid request
        }

        $topic = Topic::create([
            'category_id' => $request->get('category_id'),
            'title' => $request->get('title'),
            'limit' => $request->get('limit'),
            'user_id' => 1
        ]);

        return response()->json([
            'success' => true,
            'topic' => $topic
        ], 200);

When the validation fails, it response with a JSON like this:

{
  "success": false,
  "errors": {
    "limit": [
      "The limit must be at least 2."
    ]
  }
}

As you can see, the "limit" field is an array. My question is, why it is an array instead of a simple string? I was trying to generate more errors for that field but I can't. Is it possible to get just one string as value for each field? Thanks in advance.

16 Aug
2 years ago

sorcjc left a reply on Laravel 5 API + AUTH For A Mobile App Or Another Web Application

Hi. I have read about JWT, and I understant the next:

  1. The user perform a first request with credentials, and the server generate and reponse a token.
  2. The user will use the token received in the header for the next requests. I hope that someone can help me with my questions: JWT reduces the amount of requests that contains the credentials, but the first request is vulnerable? If the first request can be protected using HTTPS, then, why we have to use a token instead of the credentials? Thank you all.
15 Aug
2 years ago

sorcjc left a reply on Checkbox Array - Old('value')

This an old post, but here is another example (using the same name for all the checkboxes, with different values):

@foreach ($categories as $category)
                            <div class="col-md-4 col-sm-6">
                                <input type="checkbox" name="categories[]" value="{{ $category->id }}" {{ ( is_array(old('categories')) && in_array($category->id, old('categories')) ) ? 'checked ' : '' }}/> {{ $category->name }}
                            </div>
@endforeach
24 Jul
2 years ago

sorcjc left a reply on Returning Values From Listeners

@pmall If I return a false from the handle method, the next listeners will be ignored? I have the next, and PhpStorm shows an alert: the function/method declared void must not return a value.

    public function handle(ContactWasRequested $event)
    {
        $contact = $event->contact;
        $user = $contact->user;

        if ($user->free_credits > 0) {
            $user->free_credits = $user->free_credits - 1;
            $user->save();
        } else if ($user->credits > 0) {
            $user->credits = $user->credits - 1;
            $user->save();
        } else {
            return false;
        }

        $contact->verified = true;
        $contact->save();
    }
```php
11 May
2 years ago

sorcjc left a reply on [Package] Laravel 5 Real-time Chat

@bluecatworks I am using an event class that implements ShouldBroadcast, and the channel name is defined in the broadcastOn method.

public function broadcastOn()
    {
        return ['test-channel'];
    }

I am using a "constant" channel, how I can use a variable channel name appending the user id? And, have you find a secure way to do it? Thanks in advance.

13 Jan
2 years ago

sorcjc left a reply on [L5] How To Use 'after' Method On Form Request

I meant, additional validation rules. If I use the "validate" method, the errors are reported automatically. But, when I use the "fails" method, I have to report the errors with additional code.

Actually I am using:

if ($v->fails())
            return [
                'success' => false,
                'errors' => $v->getMessageBag()->toArray()
            ];

After this condition, there are more validations in my method. In these lines, I define my own "errors" array. In my previous question I was asking for a magic method like this:

$this->validate($request, [
    ...    
])->after(function($validator)
{
    if ($this->somethingElseIsInvalid())
    {
        $validator->errors()->add('field', 'Something is wrong with this field!');
    }
});

And that imaginary method doesn't require to use "fails".

Sorry for my bad english. Thank you.

08 Jan
2 years ago

sorcjc left a reply on [L5] How To Use 'after' Method On Form Request

@bobbybouwmann I saw that code in the docs, but I still don't know how to use that.

The "validate" method (in the first code) is really great. And the second way allow us to customize the validations, but after adding new errors to the "bag errors", how I can report that to the view?

Is not possible to use the "validate" and "after" method together?

Thanks.

21 Nov
3 years ago

sorcjc left a reply on Laravel 5 Image Upload And Resize.

Hi. If I just need to upload an image (without resize), can I use only the Storage class?

22 Mar
3 years ago

sorcjc started a new conversation A Question About App/Services/Registrar.php

Hi. I have a question, and I hope that you can help me.

I wanted to do some changes in the registration. Then, I added new fields for the User model and its respectively validations.

To do it I modified two files: AuthController and Registrar class, and it works perfectly.

But now, I want to add other type of users, with different fields. I alredy set it on the database. I will use the same model (User) but I have other tables with additional fields.

Because I need two forms, I have two methods getLogin and two methods getRegister in my AuthController class (with different names, obviusly). The same for postLogin and getLogin.

My problem is that I only have one Registration class.

Before, I used the instance $registrar (property of the AuthController class) without problems, but now, I want to have other Registrar class (so I will can validate and create new users using different ways).

I was thinking to create RegistrarA and RegistrarB. Both implements RegistrarContract (Illuminate\Contracts\Auth\Registrar).

But, how I can inject one instance of RegistrarB in AuthController to be used in the new methods?

Actually, by default, this class have the property $registrar, but I don't know how is it possible, because I don't see the instantiation anywhere. Probably it is using "Dependency Injection", but, how I can do it?

Sorry for my bad english. And thanks in advance.

15 Mar
3 years ago

sorcjc left a reply on Parameters In Implicit Controllers

I already solved the error using an optional parameter and adding "=null" in the argument of the method. Do you know how to write this code better?

        if(!isset($promoter))
            return redirect('auth.login')
                ->withErrors([
                    'promoter' => 'Usted necesita una invitación.'
                ]);

Thanks again.

sorcjc left a reply on Parameters In Implicit Controllers

Ok. After the replace I got:

  • auth/register: In this route the same error (MethodNotAllowedHttpException in RouteCollection.php)
  • auth/register/test: Here "test" is printed

I should change the parameter as optional? Thanks for answer. I always try to solve the error reading the messages, but in this case the message was not useful for me.

sorcjc started a new conversation Parameters In Implicit Controllers

I was using the default authentication of Laravel 5. The default code in routes.php is:

Route::controllers([
    'auth' => 'Auth\AuthController',
    'password' => 'Auth\PasswordController',
]);

But now I want to use parameters in the registration page. It is because that each new user needs an invitation from an existing user (each user have to be a referral from other). I looked for a way to use parameters with implicit controllers (using the default code, quoted before), but I didn't find it. So, I changed the default code. I remove the 'auth' (first element of the array passed as argument to Route::controllers). And type this code next:

Route::get('auth/register/{promoter}', 'Auth\AuthController@getRegister');
Route::post('auth/register/', 'Auth\AuthController@postRegister');
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

Without the parameter "promoter" the registration, login and logout works fine. But with the {promoter} parameter I get an error: MethodNotAllowedHttpException in RouteCollection.php line 207

Why? I'm triying to use this parameter in the getRegister method:

    public function getRegister($promoter)
    {
        if(!isset($promoter))
            return redirect('auth.login')
                ->withErrors([
                    'promoter' => 'Usted necesita una invitación.'
                ]);
        $paises = Pais::all();
        $paquetes = Package::all();
        return view('auth.register')->with( compact('promoter', 'paises', 'paquetes') );
    }

Anyway, the problem is not in the method, because I replaced it with a simple return of string and the error persists. The problem is in the routes, but apparently the sintaxys is correct :s

Please, help me. Thanks in advance. PD: Sorry for my bad english.