gputignano

gputignano

Member Since 4 Years Ago

Ceglie Messapica

Experience Points 18,365
Experience Level 4

1,635 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 213
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.

07 Jun
3 months ago

gputignano started a new conversation Set Default Value For Route Model Binding

Hi have this route:

Route::get('{slug?}', 'SlugsController');

and a controller with this signature:

public function __invoke(Slug $slug)
{

All works fine but for root '/' I get error. Is there a way to set a default value for route model binding ('home' instead of null)?

18 May
3 months ago

gputignano left a reply on Form Request Validation Redirect

@SNAPEY - Where the default json response is created in code? And where can I intercept it to add headers?

gputignano left a reply on Form Request Validation Redirect

I read in documentation that for AJAX requests Form Request Validation already returns JSON. However I need return something like belove using Form Request Validation:

return response()->json([
    'aaa' => 'bbb'
])->withHeaders([
    'AMP-Access-Control-Allow-Source-Origin' => 'https://127.0.0.1',
    'Access-Control-Expose-Headers' => 'AMP-Access-Control-Allow-Source-Origin',
]);

gputignano left a reply on Form Request Validation Redirect

@SNAPEY - Thanks, but how can I intercept the exception in Form Request class?

gputignano left a reply on Form Request Validation Redirect

I'm usin AMP so my forms send a XHR request and wait for a JSON response and then eventually redirect. If I use Form Request Validation when the validation fails I get an error in AMP.

gputignano started a new conversation Form Request Validation Redirect

How can I control the redirection after a Form Request Validation? Which is the class/method that make redirection?

09 Apr
5 months ago

gputignano started a new conversation Response For AMP

    public function store(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'name' => 'required',
            'email' => 'required|email',
            'active' => 'required',
            'company_id' => 'required'
        ]);

        if($validator->fails()) {
            return response()->json([
                "errors" => $validator->errors()
            ])
            ->header('Access-Control-Expose-Headers', 'AMP-Access-Control-Allow-Source-Origin, AMP-Redirect-To')
            ->header('AMP-Access-Control-Allow-Source-Origin', 'https://127.0.0.1')
            ->header('AMP-Redirect-To', url('customers/create'));
        }

        $customer = Customer::create($request->all());

        return response()->json([
            "customer" => $customer
        ])
        ->header('Access-Control-Expose-Headers', 'AMP-Access-Control-Allow-Source-Origin, AMP-Redirect-To')
        ->header('AMP-Access-Control-Allow-Source-Origin', 'https://127.0.0.1')
        ->header('AMP-Redirect-To', url('customers'));
    }

I'm using this code to validate a form input in an application with Laravel and AMP. How can I flash validation errors? In particular how can I flash errors in session? And flash old value?

04 Apr
4 years ago

gputignano left a reply on Insert In Database 404 Error Url

How can I solve?

gputignano left a reply on Insert In Database 404 Error Url

In documentation I found:

To register the error handler, listen for the ModelNotFoundException

use Illuminate\Database\Eloquent\ModelNotFoundException;

App::error(function(ModelNotFoundException $e)
{
    return Response::make('Not Found', 404);
});

Where can I insert this code?

gputignano started a new conversation Insert In Database 404 Error Url

I need to create a table containing all 404 urls. Where and how can I catch them?

gputignano left a reply on Istantiate Class From String

I resolved in this way:

Route::get('{path}', 'RouteController@show')->where('path', '.*');

to manage route including '/' so I can catch also 'category/subcategory/...' and then find the path in the table and get the owner.

    public function show($path, Request $request)
    {
            $route = Route::where('path', $path)->first();

            $item = $route->routeable;
            
            return view($route->routeable_type . '.show', compact('item', $item));
    }
03 Apr
4 years ago

gputignano left a reply on Istantiate Class From String

@rodrigo.pedra Perfect! It was easier than I thought.

gputignano started a new conversation Istantiate Class From String

In a polymorphic relation I get from owner_type field the name of the class. Now how can I get the object to pass to the view? For example if owner_type is 'App\Product' and owner_id is 1 how can I get the object of type Product with id=1?

gputignano left a reply on 2 Or More Constraints In Route

How can I solve in the case I have a ierarchical category? For example in one case I have 'cat1', in other case 'cat1/subcat1' or 'cat1/subcat2/subcat3/subcat4', etc. This case is dinamic.

gputignano left a reply on 2 Or More Constraints In Route

Ok, many thanks.

gputignano left a reply on 2 Or More Constraints In Route

@usman I know but I need the path 'one/two' to search it in a database table and see who it belongs to when I create a polymorphic relation. For example if I get 'wine/red', then I search it in the database and I get that it belongs to a category (category table) but if I get 'brunello/montalcino' I find that it belongs to a product (product table).

gputignano started a new conversation 2 Or More Constraints In Route

I created a route like this:

Route::get('/', 'RouteController@index');
Route::get('{request_path}', 'RouteController@index');

I want to catch urls like one/two using the second rule but I get error. 'request_path' should catch 'one/two' and not only 'one'. How can I solve?

24 Mar
4 years ago

gputignano started a new conversation Illuminate Vs Collective Html

I used Illuminate\Html package but then I read about Collective\Html one. Which is the difference?

20 Mar
4 years ago

gputignano left a reply on Intervention Image Package

It's right!

gputignano started a new conversation Intervention Image Package

I installed Intervention Image package and also crated a Model called Image. In ImageController I set

use App\Image as Img;

to avoid conflicts. When I use Image::make() in store method I get:

FatalErrorException in ImageController.php line 38:
Class 'App\Http\Controllers\Image' not found
17 Mar
4 years ago

gputignano started a new conversation Validate Related Model Form Field

Product model:

field 'name' | required function route (hasOne)

Route model:

field 'path' | required function owner (morphTo)

I use ProductRequest to validate name field in Product. Mi question is how can I validate also path field after I submit a form?

04 Mar
4 years ago

gputignano left a reply on Polymorphic Relations Problem

I can't find it in documentation. However I tried it and worked. Where can I find a complete documentation?

gputignano left a reply on Polymorphic Relations Problem

No, I have only one photo for each staff but I need to use polymorphic relation to relate photo to other models too.

gputignano left a reply on Polymorphic Relations Problem

I used the schema in the example:

class Photo extends Model {
    public function imageable() {
        return $this->morphTo();
    }
}

class Staff extends Model {
    public function photos() {
        return $this->morphMany('App\Photo', 'imageable');
    }
}

class Order extends Model {
    public function photos() {
        return $this->morphMany('App\Photo', 'imageable');
    }
}

Database schema:

staff
    id - integer
    name - string

orders
    id - integer
    price - integer

photos
    id - integer
    path - string
    imageable_id - integer
    imageable_type - string

I want to list all Staff member and related image on the same row, for ex.

name (Staff)    | path (Photo)
Pippo           | pippo.jpg
Pluto           | pluto.jpg

gputignano started a new conversation Polymorphic Relations Problem

I read documentation about Laravel 5 eloquent. I have problems if I want show in a single view file Staff name and Photo path. This 2 fiens are in different tables. How can I resolve?

02 Mar
4 years ago

gputignano left a reply on Product Controller

I tried on a fresh install and as guest I can access root, but after access if I visit root I get redirected to /home. If I set in RedirectIfAuthenticated.php file return new RedirectResponse(url('/')); I get a redirect loop. How can I let to a customer after login to access home page?

28 Feb
4 years ago

gputignano left a reply on Product Controller

I tried but I get always redirection loop error. I think is a problem related to routes, this is the file:

Route::get('{slug}', 'FrontController@show');
Route::get('/', 'FrontController@index');

Route::group(['middleware' => 'auth', 'prefix' => 'admin'], function() {
    Route::model('addresses', 'App\Address');
    Route::resource('addresses', 'AddressController');

    Route::model('manufacturers', 'App\Manufacturer');
    Route::resource('manufacturers', 'ManufacturerController');

    Route::model('products', 'App\Product');
    Route::resource('products', 'ProductController');

    Route::model('users', 'App\User');
    Route::resource('users', 'UserController');
    
    Route::model('vintages', 'App\Vintage');
    Route::resource('vintages', 'VintageController');
});

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

gputignano left a reply on Product Controller

Using the route:

Route::get('/', 'FrontController@index');
Route::get('{slug}', 'FrontController@show');

I can visit the home page as guest but after login I get a redirect loop. I checked kernel.php file and saw that there is this line of code:

'guest' => 'App\Http\Middleware\RedirectIfAuthenticated',

but I can't resolve yet.

gputignano left a reply on Product Controller

The problem was that I used

action('ProductController@show', $product->id)

to get the product url in home page. Now I corrected it in

url( '/', [$product->slug])

and all works well. Many thanks.

gputignano started a new conversation Product Controller

I created a ProductController.php file and a resource router for this controller:

Route::group(['middleware' => 'auth', 'prefix' => 'admin'], function() {
    Route::model('products', 'App\Product');
    Route::resource('products', 'ProductController');
});

I use all methods within ProductController for administration purpose. I want to use show method for frontend site. But when I use:

Route::get('{slug}', 'FrontController@show  ');

I get an url like

http://misite.com/admin/products/slug

but I need a url like:

http://misite.com/slug

The question is if I need a different controller for this or a closure is the best choice?

19 Feb
4 years ago

gputignano started a new conversation Customers Vs Users

Accordind to your experience in an ecommerce site create 2 separate tables (the first for customers and the second for admins) is better than create one only table for both?

gputignano left a reply on Use 'namespace' In Group

|        | GET|HEAD                       | admin/products                                        | admin.products.index   | App\Http\Controllers\Admin\ProductController@index         | auth       |
|        | GET|HEAD                       | admin/products/create                                 | admin.products.create  | App\Http\Controllers\Admin\ProductController@create        | auth       |
|        | POST                           | admin/products                                        | admin.products.store   | App\Http\Controllers\Admin\ProductController@store         | auth       |
|        | GET|HEAD                       | admin/products/{products}                             | admin.products.show    | App\Http\Controllers\Admin\ProductController@show          | auth       |
|        | GET|HEAD                       | admin/products/{products}/edit                        | admin.products.edit    | App\Http\Controllers\Admin\ProductController@edit          | auth       |
|        | PUT                            | admin/products/{products}                             | admin.products.update  | App\Http\Controllers\Admin\ProductController@update        | auth       |
|        | PATCH                          | admin/products/{products}                             |                        | App\Http\Controllers\Admin\ProductController@update        | auth       |
|        | DELETE                         | admin/products/{products}                             | admin.products.destroy | App\Http\Controllers\Admin\ProductController@destroy       | auth       |

gputignano left a reply on Use 'namespace' In Group

@bashy On the index page I get a list of products.

gputignano left a reply on Use 'namespace' In Group

@bashy Now I get

FatalErrorException in UrlGenerator.php line 440: Call to a member function domain() on null

in UrlGenerator.php line 440 at HandleExceptions->fatalExceptionFromError(array('type' => '1', 'message' => 'Call to a member function domain() on null', 'file' => 'C:\xampp\htdocs\laravel5\vendor\laravel\framework\src\Illuminate\Routing\UrlGenerator.php', 'line' => '440')) in HandleExceptions.php line 116 at HandleExceptions->handleShutdown()

gputignano left a reply on Use 'namespace' In Group

My route file is:

Route::group(['middleware' => 'auth', 'prefix' => 'admin', 'namespace' => 'Admin'], function() {
    Route::model('products', 'App\Product');
    Route::resource('products', 'ProductController');
}

I moved ProductController.php under app\Http\Controllers\Admin\ folder.

gputignano left a reply on Use 'namespace' In Group

Done but it doesn't work.

gputignano started a new conversation Use 'namespace' In Group

I successfully added 'prefix' to grouped routes but I can't understand how to use 'namespace'. After I add 'namespace' => 'Admin' to grouped route I move my ProductController under App\Http\Controllers\Admin\ folder but I get the error message: Class App\Http\Controllers\Admin\ProductController does not exist.

17 Feb
4 years ago

gputignano left a reply on Register Only By Email And Password

@bestmomo

You are right. After login I get redirected to the previous url and that was /home. When I visit /auth/login as start page I get redirected to /dashboard.

gputignano left a reply on Register Only By Email And Password

However on a fresh installation of L5 I added the line above but after logging in I get redirect to /home

class AuthController extends Controller {

        protected $redirectTo = '/dashboard';
    .....
14 Feb
4 years ago

gputignano started a new conversation Npm Install Warning

I'm watching laracasts videos and 19 Manage Your Assets explain how to instal npm using the command:: npm install. But I get the message:

npm WARN package.json @ No repository field.

on window system.

package.json content is:

{
    "devDependencies": {
            "gulp": "^3.8.8",
            "laravel-elixir": "*"
    }
}
12 Feb
4 years ago

gputignano left a reply on Mutator Doesn't Work

Now it is clear infact it works.

gputignano started a new conversation Mutator Doesn't Work

I use below code in Article.php model to modify articles titles but it seems not to work. What's wrong?

class Article extends Model {
    protected $fillable = array(
            'title',
            'body',
            'published_at'
        );

        public function setTitleAttribute($title) {
            $this->attributes['title'] = strtolower($title);
        }
}
09 Feb
4 years ago

gputignano left a reply on Register Only By Email And Password

Ok, many thanks to all.

gputignano left a reply on Register Only By Email And Password

It works. But where is set /home?

gputignano left a reply on Register Only By Email And Password

I have another question: after login I get redirected to /home, how can I change this route?

gputignano started a new conversation Register Only By Email And Password

In Laravel 5 I tried to remove code in form relate to name and eliminate 'name' from fillable variable. But I get 'The name field is required'. Where I missing to correct this field?