Squire

Squire

Member Since 8 Months Ago

Experience Points
6,840
Total
Experience

3,160 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
62
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.

Level 2
6,840 XP
Oct
30
3 weeks ago
Oct
22
1 month ago
Activity icon

Started a new Conversation Get Specific Columns Using FirstOrFail

Hello, is there a way to use first or fail and also get only some columns?

I have a table which have a lot of columns, so, excluding all of those tables is likely not an option. I was using this: return $this->where([$filter => $identifier, 'Password' => $password])->get(['project_id', 'first_name']);

and it works fine, but I want it to throw the not found exception if doesn't find anything in the db

Oct
19
1 month ago
Activity icon

Replied to Socialite Auth Without Using Database

So I went to sleep and now with a fresh mind it comes obvious to me that I cannot do that since Auth uses the database for other stuff.

Now the question would be: Can I approach this using session()? is it secure to store there the google token?

Oct
18
1 month ago
Activity icon

Started a new Conversation Socialite Auth Without Using Database

I was just wondering if there's a way to use Auth with socialite without having to create an user model and table. Since I'm only allowing a certain domain to be able to login with google oauth I don't need any extra information. I just want to know that the people trying to access my website have access to the domain email, that's it.

But everywhere I read, the only way to use Auth is with a laravel authenticable instance... I just want to do something like Auth::login(Socialite::driver('google')->user())

Any suggestion? Is it secure to save the Socialite instance in the session?

Oct
13
1 month ago
Activity icon

Replied to Mailgun Not Sending Email, How To Debug

Just figured out that I didn't have to setup MAILGUN_ENDPOINT, so just removed it from .env and it worked.

Activity icon

Started a new Conversation Mailgun Not Sending Email, How To Debug

I'm trying to use Mailgun as my mail driver but the emails are not being sent. I don't know how to debug this, I tried changing the mail driver to log and see what's going on there but all seems fine.

My .env is configured like this:

MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

MAILGUN_DOMAIN=mg.mydomain.com
MAILGUN_SECRET=xxxxxxxxbdebc8829bf2d871xxxxxxx-af6c0cec-xxxxxxxx
MAILGUN_ENDPOINT=api.mailgun.net/v3/mg.mydomain.com

This is not working neither in my local enviroment (homestead) nor in production (laravel forge)

Oct
11
1 month ago
Activity icon

Replied to Laravel And Vue - Popper Error

Any solution for this? I'm facing the same issue

Aug
29
2 months ago
Activity icon

Replied to Method Not Allowed On Axios Post Request With Vue And Laravel

Hey thank you for replying. I'm not trying to update, in the beginning of the thread I wrote this: "and I have to do a post request to '/projects' to create a resource."

I have nothing in my api.php, I also wrote that I created the route in the web.php file: "I'm registering the routes in my web.php like this:"

Thank you!

Activity icon

Commented on Object-Oriented Forms: Part 1

I'm getting a method not allowed error with the post request to Projects, here I explain further my issue: https://laracasts.com/discuss/channels/code-review/method-not-allowed-on-axios-post-request-with-vue?page=1#

any help is appreciated

Activity icon

Replied to Method Not Allowed On Axios Post Request With Vue And Laravel

Yeah I tried it before, forgot to mention it in the post

Activity icon

Started a new Conversation Method Not Allowed On Axios Post Request With Vue And Laravel

Hi guys, so I'm following up this course: https://laracasts.com/series/learn-vue-2-step-by-step/episodes/19

and I have to do a post request to '/projects' to create a resource.

I created my ProjectController with the artisan command using the --resource modifier and I'm registering the routes in my web.php like this:

Route::resource('projects', 'ProjectController');

If I run the route:list, I get this: https://i.imgur.com/gx4xOsa.png

And my Vue component with the Axios request:

new Vue({
    el: '#app',

    data: {
        name: '',
        description: ''
    },

    methods: {
        onSubmit: function () {
            axios.post('projects', {
                name: this.name,
                description: this.description
            });
        }
    }
});

I don't know what's going on, I'm stuck here. The resource route is creating the post method for projects...

This is the Axios response (405): message The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, PATCH, DELETE.

EDIT: I also tried with /projects instead of project in the axios request

Aug
25
2 months ago
Activity icon

Commented on Workshop - Card Design

how can I access those assets, the book and the clock for example

Aug
19
3 months ago
Activity icon

Commented on A Project Requires An Owner

public function test_a_project_requires_an_owner()
    {
        $this->withoutExceptionHandling();
        $attributes = factory('App\Project')->raw(['owner_id' => null]);
        $this->post('/projects', $attributes)->assertSessionHasErrors('owner_id');
    }

That test was giving me this error: The given data was invalid, once I removed the withoutExceptionHandling() the test passed.

Activity icon

Commented on Model Tests

that forelse blew my mind, didn't know that exists!

Aug
18
3 months ago
Activity icon

Replied to Will I Be Charged Monthly?

Do I have to do it near my subscription end or can I do it like right now so I don't foget to do it later?

Activity icon

Started a new Conversation Will I Be Charged Monthly?

My sister paid for me the monthly subscription but she said that she doesn't want to get charged monthly without her knowing it. How does laracast work? Do I have to manually pay for my next month or will it do it automatically?

Aug
10
3 months ago
Activity icon

Replied to Would Like To Get Feedback In My First Package

Thank you! It's a small package tho :( still developing it.

These doubts put me in a non ending loop where I read articles after articles about designs and how to write good code (time where I do not code at all) and I end up procrastinating

Activity icon

Started a new Conversation Would Like To Get Feedback In My First Package

Hello guys. So I've been into programing for 1 and a half year now and I've been spending the last 7 months learning Laravel. I wanted to do something different aside from the normal backend services for applications so I decided to try with a package.

I read a couple of tutorials regarding the folder structure and what I had to do to made it available in composer and all that stuff. But anyways, these are my biggest concerns right now:

  1. I'm developing it to be used only with Laravel, but I've read a lot of threads where people talk about packages should be general use, not framework orientated. What should be the best approach to achieve this?

  2. All the logic is inside one single class. I've been thinking that I can separate some stuff to improve the readability and scalability, but that would make me loss my one single facade feature. What do you recommend me?

  3. I've read that one shouldn't enforce developers to use facades but give them the option to choice between that or dependency injection. How can I make sure that my package can work thorugh dependency injection too?

  4. And this one may sound stupid but I had a tough time trying to choose the name of my logic class. First off, I placed it inside a "Helpers" class and then named it "UrlShortenerHelper" (I don't remember why) but then today I named the whole thing to "Services/UrlShortenerService" because it made more sense to me. Is there any naming convention for this kind of stuff? I'm very used to laravel convention for classic backend services naming convention, like controllers have the name of the resource in singular followed by the controller name and stuff like that.

Thank you for taking the time of read my code. This is the repository: https://github.com/cedaesca/urlshortener

Jul
08
4 months ago
Activity icon

Started a new Conversation Laravel Forge: Deploy From Monorepo

Hello, I paid Laravel Forge and a Digital Ocean droplet and when trying to deploy from my repo which is structured like this:

backend
    /laravelRoot
frontend
    /angularRoot

but it gave me an error. What would be the best approach to deploy both frontend and backend? there's something I have to edit? any resource you can give me so I can read?

May
25
5 months ago
Activity icon

Started a new Conversation Class Not Found In Package's Controller

So, I'm following a tutorial to create a package and I have the following structure:

root/packages/vendor/package/src

And in the src folder I have the following files:

routes.php (For routing):

<?php
namespace cedaesca\URLShortener;

Route::get('cedaesca/urlshortener/create', 'cedaesca\URLShortener\[email protected]')->name('cedaesca/urlshortener/create');
Route::post('cedaesca/urlshortener/store', 'cedaesca\URLShortener\[email protected]')->name('cedaesca/urlshortener/store');

ShortenedUrl (model)

<?php

namespace cedaesca\URLShortener;

use Illuminate\Database\Eloquent\Model;

class ShortenedUrl extends Model
{

    /**
     * Fillable columns for model's mass assignment
     *
     * @var array
     */
    
    protected $fillable = [
        'shortlink',
        'target',
        'title',
        'description'
    ];

    /**
     * Custom table for the current model
     *
     * @var string
     */

    protected $table = 'shortenedurls';

    /**
     * URL's code length
     *
     * @var integer
     */
    
    public $length = 4;

    /**
     * If the code doesn't exist, it redirects to this default
     *
     * @var string
     */

    public $defaultRedirect = '/';

    /**
     * Genearet an unique code that will serve as an URL parameter
     *
     * @return string
     */

    public function generateCode() {

        $extraCharacter = '';

        if( $this->length % 2 != 0 ) {

            $extraCharacter = bin2hex( random_bytes(4) );
            $extraCharacter = substr( $extraCharacter, -1 );

        }

        do {

            $code = bin2hex( random_bytes( $this->length / 2 ) ) . $extraCharacter;

        } while( $this->checkIfExists('shortlink', $code) );

        return $code;
        
    }

    /**
     * Check if there are records for the specified column with the given value
     *
     * @param string $type
     * @param string|integer $value
     * @return boolean
     */

    public function checkIfExists($type, $value) {

        $collection = $this::where($type, $value)->first();

        if( !is_null( $collection ) ) {

            return true;

        }

        return false;

    }
    
}

UrlShortenerController (controller)

<?php

namespace cedaesca\URLShortener;

use Illuminate\Http\Request;
use ShortenedUrl;
use Illuminate\Support\Facades\Route;

class UrlShortenerController extends Controller
{
    public function create() {

        return view('url.create');

    }

    /**
     * Store a new record in the shortenedurls table
     *
     * @return json
     */

    public function store(Request $request) {

        $validatedData = $request->validate([

            'target' => 'required|max:255'

        ]);

        $shortenedUrl = new ShortenedUrl;

        $shortenedUrl = $shortenedUrl::create([

            'shortlink' => $shortenedUrl->generateCode(),
            'target' => $request->target,
            'title' => $request->title,
            'description' => $request->description

        ]);

        if( $shortenedUrl->id ) {

            return response()->json([
                'message' => 'Created successfully',
                'data' => [
                    'id' => $shortenedUrl->id,
                    'shortenedlink' => $shortenedUrl->shortlink,
                    'title' => $shortenedUrl->title,
                    'description' => $shortenedUrl->description,
                    'created_at' => $shortenedUrl->created_at
                ]
            ], 201);

        }

        return response()->json([
            'message' => 'Occured an error while trying to create a shortened URL, try again'
        ]);

        

    }

    /**
     * Check if there are records for the specified column with the given value
     *
     * @param string $code
     * @return object
     */

    public function redirect($code) {

        $shortenedUrl = new ShortenedUrl;
        
        $collection = ShortenedUrl::where('shortlink', $code)->first();

        if( ! is_null( $collection ) ) {

            return redirect($collection->target);

        }

        return redirect($shortenedUrl->defaultRedirect);

    }
}

URLShortenerServiceProvider (service provider)

<?php

namespace cedaesca\URLShortener;

use Illuminate\Support\ServiceProvider;

class URLShortenerServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        $this->loadRoutesFrom(__DIR__.'/routes.php');
    }
}

Now, when I try to access /cedaesca/urlshortener/create I get this error:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Class 'cedaesca\URLShortener\Controller' not found

I added the class in the composer's autoload section:

"autoload": {
        "psr-4": {
            "App\": "app/",
            "cedaesca\URLShortener\": "packages/cedaesca/URLShortener/src"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },

And dumped the autoload with composer dump-autoload

What am I missing? I didn't find anything controller related in the laravel's pacakge documentation :/

May
18
6 months ago
Activity icon

Started a new Conversation Create URL's From UI

Hello guys,

I want to create an URL shortener but I don't really know how to generate new routes from an UI. Any suggestion or article I can read?