sergionader

Experience

6,350

0 Best Reply Awards

  • Member Since 10 Months Ago
  • 55 Lessons Completed
  • 8 Favorites

4th September, 2018

sergionader left a reply on Get The Value Of A Signed Route. • 2 weeks ago

Hey guys,

@aurawindsurfing, the URL was a typo, thanks

@newbie360, I created a middleware and now it's working the way I need. Thanks!

1st September, 2018

sergionader left a reply on Get The Value Of A Signed Route. • 2 weeks ago

Thanks, @aurawindsurfing I understand how that works.

I am not getting is the following:

  1. User visits http://localhost:8000/test/11?signature=89ffe6d8348dbcbf1b36fb97421742a48d959a7998078c77365922279075455d

  2. route validates it

  3. if not ok, abort

  4. if ok, pass the id to a controller that will show a page.

Any ideas?

Thanks and have a great weekend!

30th August, 2018

sergionader left a reply on Get The Value Of A Signed Route. • 3 weeks ago

@newbie360, you are correct. Thanks!

@aurawindsurfing, I had done the validating thing as well, but this is not the point. After validating, how can I know who the user to unsubscribe it? Is there any way other than Route::current()->parameters;?

Thank you!

sergionader started a new conversation Get The Value Of A Signed Route. • 3 weeks ago

Hey!

Following https://laravel.com/docs/5.7/urls#signed-urls I generated a signed route:

URL::signedRoute('unsubscribe', ['user' => 1]);
http://localhost:8000/unsubscribe/1?signature=d1964b9477471fa9d0004176f36687928c12a9bb7a4d5085fcb0f334a6398860"

As you can see the URL has the user, 1, and signature, d1964b9....

The route is:

...
})->name('unsubscribe');

I want to retrieve the user. None of these will show it:

$request->all(); result: {"signature":"d1964b9477471fa9d0004176f36687928c12a9bb7a4d5085fcb0f334a6398860"}

$request->user(); result: null

$request->input('user'); result: null

No error is thrown

Any ideas?

Thanks!

31st July, 2018

sergionader left a reply on How To Apply HTML Tags Inside A Bootstrap Alert Box? • 1 month ago

Hi, Cronix. Done!

30th July, 2018

sergionader left a reply on How To Apply HTML Tags Inside A Bootstrap Alert Box? • 1 month ago

Thanks, @lostdreamer_nl It worked -- how could I have missed it....? :-) Regards!

sergionader started a new conversation How To Apply HTML Tags Inside A Bootstrap Alert Box? • 1 month ago

Hi!

It seems very basic, but I couldn't find a solution.

  1. I have a controller that will call a blade: return redirect()->route('app.vendor.search', [$variables])->with('info-success', 'File uploaded successfully.');
  2. the blade has the following code:
                <div class="alert alert-success alert-dismissible">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                    <h4>
                        <i class="icon fa fa-check"></i> Success!</h4>
                        {{ Session::get('info-success') }}
                </div>
            @endif```
3) It works very  well. 
4) However, if I try something like 
`....)->with('info-success', 'File <strong>uploaded<strong> successfully.'); ` the "strong" tag will be ignored. As matter of fact all the tags I've tried we ignored. 

Any ideas? 

Thanks  !!

sergionader left a reply on Slack - Message Error Content • 1 month ago

Thanks, @ohffs !

I will give it a try.

Sergio

27th July, 2018

sergionader started a new conversation Slack - Message Error Content • 1 month ago

Hello. I set up my server to send a slack message every time an error occurs -- it works perfectly.

However, the message we got lacks some vital information -- for instance, I don't know what was the code (file/line) that failed.

Please take a look here: https://screencast.com/t/vWXLnHOssQ

Is there a way to set to messages to be more useful?

Thanks!!

1st June, 2018

sergionader left a reply on Users X Unique Email • 3 months ago

Hey @Cronix

Typo was my first attempt, but the "class" (that is a table, in fact) comes from here.

'email' => 'required|email|unique:*users*',

I just made another test and tried to validate the field using another table, dealers:

`$rules = ['email' => 'required|unique:dealers,name'];``

Guess what? No error at this time. I really seems to (very well) hidden somewhere....

31st May, 2018

sergionader left a reply on Users X Unique Email • 3 months ago

Hey @Snapey. Unfortunately not. There is just the 500 server error

**** Symfony\Component\HttpKernel\Exception\HttpException: Class users does not exist in /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:284
Stack trace:
#0 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(187): Illuminate\Foundation\Exceptions\Handler-&gt;prepareResponse(Object(Illuminate\Http\Request), Object(ReflectionException))
#1 /var/www/html/timesaver/app/Exceptions/Handler.php(60): Illuminate\Foundation\Exceptions\Handler-&gt;render(Object(Illuminate\Http\Request), Object(ReflectionException))
#2 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(83): App\Exceptions\Handler-&gt;render(Object(Illuminate\Http\Request), Object(ReflectionException))
#3 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): Illuminate\Routing\Pipeline-&gt;handleException(Object(Illuminate\Http\Request), Object(ReflectionException))
#4 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#5 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Routing\Middleware\SubstituteBindings-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#6 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#7 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(43): Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#8 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Auth\Middleware\Authenticate-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#9 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#10 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#11 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\View\Middleware\ShareErrorsFromSession-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#12 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#13 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(63): Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#14 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Session\Middleware\StartSession-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#15 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#16 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#17 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#18 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#19 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#20 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Cookie\Middleware\EncryptCookies-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#21 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#22 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#23 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Router.php(661): Illuminate\Pipeline\Pipeline-&gt;then(Object(Closure))
#24 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Router.php(636): Illuminate\Routing\Router-&gt;runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#25 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Router.php(602): Illuminate\Routing\Router-&gt;runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
#26 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Router.php(591): Illuminate\Routing\Router-&gt;dispatchToRoute(Object(Illuminate\Http\Request))
#27 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\Routing\Router-&gt;dispatch(Object(Illuminate\Http\Request))
#28 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Foundation\Http\Kernel-&gt;Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#29 /var/www/html/timesaver/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#30 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Fideloper\Proxy\TrustProxies-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#31 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#32 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(31): Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#33 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Foundation\Http\Middleware\TransformsRequest-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#34 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#35 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(31): Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#36 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Foundation\Http\Middleware\TransformsRequest-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#37 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#38 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#39 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Foundation\Http\Middleware\ValidatePostSize-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#40 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#41 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(51): Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#42 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#43 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#44 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#45 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\Pipeline\Pipeline-&gt;then(Object(Closure))
#46 /var/www/html/timesaver/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel-&gt;sendRequestThroughRouter(Object(Illuminate\Http\Request))
#47 /var/www/html/timesaver/public/index.php(55): Illuminate\Foundation\Http\Kernel-&gt;handle(Object(Illuminate\Http\Request))
#48 {main}

sergionader left a reply on Users X Unique Email • 3 months ago

Hey @jake.admin@gmail.com. Thanks but it's not working. It worked on a fresh install but it has to work on the live system.

I will keep researching and until I find a solution, I will manually check the email uniqueness.

30th May, 2018

sergionader left a reply on Users X Unique Email • 3 months ago

@jake.admin@gmail.com, your suggestions to use $this-> was good but no success. I tried both ways you suggested and it didn't work.

And even if the ways I was using was not the best ($request->validate( $rules, $customMessages); it did work on a fresh Laravel install...

There is something somewhere else that is being called just before the error is thrown....

sergionader left a reply on Users X Unique Email • 3 months ago

Hey @jake.admin@gmail.com, the error happens regardless what is or is not in the email variable. Also, it happens with or without the required.

@snapey the error happens on line 362: /vendor/laravel-doctrine/orm.src/IlluminateRegistry.php

(362)--> $proxyClass = new ReflectionClass($class);
               if ($proxyClass->implementsInterface(Proxy::class)) {
                   $class = $proxyClass->getParentClass()->getName();
               }

sergionader left a reply on Users X Unique Email • 3 months ago

Hey @jake.admin@gmail.com,

In a fresh installation, it worked.... trying to figure out what is wrong if my current project.

sergionader left a reply on Users X Unique Email • 3 months ago

Thanks for the reply.

Yes, the 'email' after the comma was meant to the field name. I am check if it is an email on the form.

Regardless, I copied and pasted your suggestion and I still get the same error. $rules = ['email' => 'required|unique:users|email'];' I also tried $rules = ['email' => 'required|unique:users'];`

Any other insight? I will try it in a fresh Laravel installation and see what happens.

sergionader left a reply on Users X Unique Email • 3 months ago

Hey @mstnorris, thanks for your reply.

This is enough to produce the error in my case. To keep it simple, I removed the name and password validation (with or without them the error will appear).

 public  function storeNewUser(Request $request){   
        $rules = ['email' => 'required|unique:users,email'];
        $email_message = 'Please enter a valid and unique email address.';    
        $customMessages = ['email.required' => $email_message];
        $request->validate( $rules, $customMessages);
        // if validated, then I will save it. 
    }

The error is pointed to be here: vendor/laravel-doctrine/orm/src/IlluminateRegistry.php

        $proxyClass = new ReflectionClass($class);
        if ($proxyClass->implementsInterface(Proxy::class)) {
            $class = $proxyClass->getParentClass()->getName();
        }

sergionader started a new conversation Users X Unique Email • 3 months ago

Hello!

I read a lot of posts about it, but can't figure out what is wrong when I try to validate an email for insertion (this for a new user).

This is the error I get through everything looks as described in the docs:

(unique:table,column,except,idColumn at https://laravel.com/docs/5.6/validation#rule-unique)

Class users does not exist

I am using "laravel/framework": "5.6.*",

Using the users table as follows:

Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->dateTime('deleted_at')->nullable(true)->default(null);
            $table->timestamps();
        });

Model:

class User extends Authenticatable
{
    use Notifiable;
    
    protected $fillable = [
        'name', 'email', 'password',
    ];
    
    public function roles()
    {
        return $this->belongsToMany('App\Role');
    } 
    
    protected $hidden = [
        'password', 'remember_token',
    ];
}```

And finally controller:

... use App\User; ... $rules = [ 'email' => 'required|unique:users,email', ]; $customMessages = [ 'email.required' => $email_message, ]; $request->validate( $rules, $customMessages);

result:
*Class users does not exist* 

sergionader left a reply on Laravel E-comm Experience & Demo • 3 months ago

Thanks for the reply, @jlrdw!

I have already searched GitHub.

For now, I have this as a strong candidate: https://aimeos.org/integrations/laravel-ecommerce-package/ However, there is no USPS native connection to it. I can see a lot of UPSP connectors for Laravel but as before I interested in some real experience.

Have anyone used a Laraval/USPS package? Any recommendation?

Thanks!

27th May, 2018

sergionader started a new conversation Laravel E-comm Experience & Demo • 3 months ago

Hello!

Is anyone running a Laravel based e-comm site? if yes, what is the URL and what are you using?

I administrate some Magento stores and though Magento is a great and very flexible product, it's kind of expensive when it comes to code-customized it,

Considering how robust and easy it is to customize Laravel solutions, I am looking for a Laravel an e-comm package that would offer at least a basic e-comm set of features, as follows: a) shopping cart; b) shipping integration with USPS (if possible) c) at least a Paypal payment gateway d) admin interface for managing products, orders, and customers; e) order status (placed, processed, shipped, etc). f) flexible blade structure for customizing the store view

It does not have to offer all the features of Magento, of course.

I see that there are some packages available for it, but most of them lack live examples.

Well, much better than live examples, is to have the impressions and comments of the Laracast community.

If you have any insights and experience with any Laravel e-comm package, I am sure that many readers would be interested in knowing them. Any suggestions will be very welcome!

Thanks!

27th March, 2018

sergionader left a reply on Update Records/pagination After Reloading The View. • 5 months ago

Snapey, it worked. The way I did it some hours ago was creating an infinite load loop.

sergionader left a reply on Update Records/pagination After Reloading The View. • 5 months ago

Thanks, Snapey. I tried it but got an error. I will try again and see what is going on.

sergionader started a new conversation Update Pagination After Reloading The View. • 5 months ago

Scenario:

  1. I have a view, dealers.blade, that shows in a the contents of a single table.
  2. the view has a pagination control,{{$dealers->links()}}, and the controller sends pagianate(10) to the view. The
  3. The records of the dealers table are added by importing an excel file.
  4. the file upload field and the importer button are in the same blade.

Question:

  1. say we have 20 dealers. When I access the view, I can see pages 1 and 2 on the pagination control. This is fine.
  2. now, using the very same page, I select a file, upload it and add to the dealers table. Dealer table now has 40 records/
  3. the pagination control should show 4 pages, but it is still showing 2 pages (because the previous count was 20 records). In other words, the view is still showing the same old 20 records.
  4. Now I import 10 more records and the view now shows 4 pages (from the previous import) instead of five.
  5. in any case, if I hit the "go to the last record" button, the pagination control is updated by itself. After importing the data, I call the view using: return view('app.dealers',[<<variables>>]);

Basically I need to show the new records when I call the view again. If the new records are show, the pagination control will be updated by itself, I guess.

TIA!

27th January, 2018

sergionader left a reply on Laravel: Fetch Data Inside A Vue Component • 7 months ago

OMG! For some reason, I thought "data" was a reserved word. Now it is:

   <country-list :countries="{{ $countries }}"></country-list>

I ketp the :.

Thanks a lot, guys!

sergionader left a reply on Laravel: Fetch Data Inside A Vue Component • 7 months ago

BTW, props is not being populated. Please see this image: https://screencast.com/t/O8x4RCEjit

For the record, I populated the table countries with dummy data, so there no real names there (using faker())

sergionader left a reply on Laravel: Fetch Data Inside A Vue Component • 7 months ago

Thanks a lot! I have done it before, but forgot to npm run watchand was struggling with an old error.

BTW, now there is no error and no data, unfortunately. To make sure $countriesis holding the data, I set up the blade like this:

    <div>
        All countries: {{$countries}}
    </div> 
    <br>
    <div>
        List of countries:
        <country-list :data="{{ $countries }}"></country-list>
    </div>

I got the data after "All countries"  but not after  "List of countries".

The component follows: 
```
Vue.component('country-list', {
    props: ['countries'], 
    template: `
        <div>
        <ul>
            <country v-for="country in countries" :key="country.id" > {{ country.name }} </country>
            </ul>
        </div>
        `,         
        data(){
            return {
                countries: this.countries
            }
        }
});
```
I also tried returning nothing as in your example, but neither of them worked. 
```
...
  data(){
            return {
                countries: this.countries
            }
        }
...
```

Any ideas? 

sergionader left a reply on Laravel: Fetch Data Inside A Vue Component • 7 months ago

I just tried

<country-list :data="{{ $countries }}"></country-list> 

what gives me a Vue error that makes sense. Kind of stuck. Researching.

sergionader started a new conversation Laravel: Fetch Data Inside A Vue Component • 7 months ago

Not sure if this is the best approach, but what I need looks to be very simple.

Let's say the application needs to show a list of countries inside a combo-box or using any other formatting. The list of countries is in a table named, say, countries and we get the data via de Country model as usual.

Instead of showing it inside a @foreach loop for all the blades it will show up, I would like to have something more modular like a Vue component.

Using the Laravel's built-in Vue component structure, I came out with the following for validating the idea:

resources/assets/js/app.js

Vue.component('country-list', {
    template: `
        <div>
        <ul>
            <country v-for="country in countries" :key="country.id" > {{ country.name }} </country>
            </ul>
        </div>
        `,
    data(){
        return {
            countries: [
                { id: 1, name: 'Australia'},
                { id: 2, name: 'Brazil'},
                { id: 3, name: 'Italy'},
                { id: 4, name: 'United States'}
            ]    
        }
    }
});
Vue.component('country', {
    template: '<li><slot></slot></li>',
})

const app = new Vue({
    el: '#app'
});

Blade:

@extends('layouts.app')
@section('content')      
    <country-list></country-list>        
@endsection

Works perfectly but as you can see, the countries are hard-coded, what is not what I want.

Considering I can fetch the countries with something like $countries = Country::all() how can I bind it to the Vue component so the <country-list></country-list> tag will show the data from the countries table?

Thanks!

27th November, 2017

sergionader left a reply on L5.5: Cache: Missing Illuminate\Database\Query\Builder::remember() • 9 months ago

Thanks. I just saw it somewhere else as well :-)

sergionader left a reply on L5.5: Cache: Missing Illuminate\Database\Query\Builder::remember() • 9 months ago

Thanks, @tykus! Worked very well. For the record, I got it from the below video: (https://laracasts.com/lessons/cache-tags-and-memcached)

Screenshot: (https://screencast.com/t/VZyDlN8tH) Other than a version issue, any reason for the divergence?

Regards!

26th November, 2017

sergionader started a new conversation L5.5: Cache: Missing Illuminate\Database\Query\Builder::remember() • 9 months ago

Hi!

Using tinker the following works:

$u = User::all();

but

$u = User::remember(10)->get();

fails with the following message:

BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::remember()'

I have redis and memcached running and tried them both by changing cache.php:

  'default' => env('CACHE_DRIVER', <<redis or memcached>>),

The user model starts like this:

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Scout\Searchable;
...

I tried to include the Cache facade (use Illuminate\Support\Facades\Cache;) with no success.

Looks like I am missing something very simple...

Thanks!!

sergionader left a reply on SQL To Eloquent -- How To Convert This Query? • 9 months ago

Thanks a lot, @Dry7

For the record, I had to make a little change to make it work.

        $sql = DB::table('visits')
        ->join('product_visit', 'visit_id', '=', 'visits.id')
        ->where('product_visit.amount', '>', 0)
        ->whereBetween('visits.dt', [$dt_start, $dt_start])
        ->groupBy('month_idx', 'year')
        ->orderBy('year', 'desc')
        ->selectRaw('DATE_FORMAT(visits.dt, \'%m\') AS month_idx')
        ->selectRaw('DATE_FORMAT(visits.dt, \'%Y\') AS year')
        ->selectRaw('ROUND(sum(product_visit.amount)) AS y')
        ->get();

if I try

...
 ->selectRaw(
            'DATE_FORMAT(visits.dt, \'%m\') AS month_idx',
            'DATE_FORMAT(visits.dt, \'%b\') AS month',
            'DATE_FORMAT(visits.dt, \'%Y\') AS year',
            'ROUND(sum(product_visit.amount)) AS y'
        )
...

I get an error saying it expects an array.

The way I did, it's now working.

25th November, 2017

sergionader started a new conversation SQL To Eloquent -- How To Convert This Query? • 9 months ago

Hello!

I have this query that works very well:

$sql = DB::select("
        SELECT
            DATE_FORMAT(visits.dt, '%m') AS month_idx,
            DATE_FORMAT(visits.dt, '%b') AS month,
            DATE_FORMAT(visits.dt, '%Y') AS year,
            ROUND(sum(product_visit.amount)) AS y
        FROM    visits, product_visit
        WHERE
            visits.id       = product_visit.visit_id
            AND product_visit.amount>0
            AND (visits.dt between '$dt_start' and '$dt_start')
        GROUP BY month_idx, month, year
        ORDER BY year desc, month_idx desc;
        ");

However, the following one will not run:

 $sql_sales_by_month = DB::table('visits')
        ->join('product_visit', 'visit_id', '=', 'visits.id')
        ->where('product_visit.amount', '>', 0)
        ->whereBetween('visits.dt', [$dt_start, $dt_start])
        ->groupby('month_idx', 'year')
        ->groupby(['year', 'desc'])
        ->select(
            'DATE_FORMAT(visits.dt, \'%m\') AS month_idx',
            'DATE_FORMAT(visits.dt, \'%b\') AS month',
            'DATE_FORMAT(visits.dt, \'%Y\') AS year',
            'ROUND(sum(product_visit.amount)) AS y'
        )
        ->get();

The error message is:

There was an error: {"readyState":4,"responseText":"{\n "message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'DATE_FORMAT(visits.dt, '%m')' in 'field list' (SQL: select DATE_FORMAT(visits.dt, '%m') as month_idx, DATE_FORMAT(visits.dt, '%b') as month, DATE_FORMAT(visits.dt, '%Y') as year, ROUND(sum(product_visit.amount)) as y from visits inner join product_visit on visit_id = visits.id where product_visit.amount > 0 and visits.dt between 2017-01-01 and 2017-01-01 group by month_idx, year, year, desc)"

Any idea of how we can make it work?

Thanks!!

21st November, 2017

sergionader left a reply on Laravel 5.5/Scout: How To Extend Scout To Use Eloquent Joins? • 9 months ago

Hello, Ccris! Thanks for the hint. I've changed back to Elastic Search two days ago - now using Erick's driver, that sorts related tables out of the box: https://github.com/ErickTamayo/laravel-scout-elastic. This driver relays on you to set up whatever you want via ES API and does a great job so far. I will soon post the complete code. Thanks!

19th November, 2017

sergionader left a reply on Laravel 5.5/Scout: How To Extend Scout To Use Eloquent Joins? • 10 months ago

Update: I give Algolia a try and:

  1. it searches very well related tables. It also has fuzzy search out of the box and a basic web interface for index management. To make it work, it's important to set up the main model. In my case, the model Visit has:
  public function toSearchableArray()
    {
        $array = $this->toArray();
        $array['products'] = $this->products->toArray();
        $array['origin'] = $this->origin->toArray();
        $array['profile'] = $this->profile->toArray();
        $array['user'] = $this->user->toArray();
        return $array;
   }

Searching is a breeze:

  $visits = Visit::search("$query")
            ->paginate(10);

Works very fast and nice but... -- and this is very annoying but -- I can't sort the resulting grid by any field I want. I dug a little and found out the following:

  1. To sort, it's necessary to create an index replica. That's easy and makes sense;
  2. only numeric fields can be sorted -- and this is very weird...
  3. for instance, to sort the date, I created a new field called dt_unix where I store strtotime($date). Then I created two indices replicas: dt_asc and dt_desc.
  4. When I want to sort I just have to indicate which index should be used. Here is how to set the index on the fly:
  $index_name = 'dt_desc';
  $visits = Visit::search("$query")
            ->within($index_name)
            ->paginate(10);
  1. However, only the fields on the main table/model can be sorted. Thus, if I want to sort Origin (by any numeric criteria I could create), there is no way to set the index to sort by a field from a related table. Maybe using an "inverted model", i.e, Origin and the "related" Visits, it can be done -- it does look very messy, kind of the patch of the workaround!

If I am missing something, please let me know. The only thing I need is to have a server paginated grid that is searchable and sortable -- sure, it's a very common thing.

As always, any ideas are welcome!

16th November, 2017

sergionader left a reply on Laravel 5.5/Scout: How To Extend Scout To Use Eloquent Joins? • 10 months ago

Hi, @CcrisS. Thanks for the post, but it won't work. The mapping shows

   "origin_name": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        },
                        "fielddata": true

but

$sort_column = 'origin_name';
$visits = Visit::search("canada")
            ->orderby($sort_column, $sort_az_za)
            ->with(['origin', 'profile', 'user'])
            ->paginate(10); 
```

will give us: 
<SQLSTATE[42S22]: Column not found: 1054 **Unknown column 'origin_name'**  in 'order clause' (SQL: select * from `visits` order by `origin_name` asc limit 10 offset 0)>

the whole problem is that the Visit model does not know the origin table even with the "with('origin') method. 

15th November, 2017

sergionader left a reply on Advanced Scout Driver For Elastic Search • 10 months ago

Hello, Babenko. I can't understand why nobody has answered to your post (I am new here). I am using your driver with success (congrats!!!). The only point I have is described in this Laracast thread.

Looks like it's not related to the driver but to way Scout users the query builder. Would you have any suggestion? Basically, I would like to be able to search and sort the results in a grid for every field and not only for those of the "main" table.

14th November, 2017

sergionader left a reply on Laravel 5.5/Scout: How To Extend Scout To Use Eloquent Joins? • 10 months ago

Thanks, Pierre! Unfortunately, it will not work.

Visit::where('column', 'LIKE', '%$query%')
->join('origins', 'origins.id', 'visits.origin_id')
->search('canada')
->get();

will produce:

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

and

$visits = Visit::search('canada')
->where('column', 'LIKE', '%$query%')
->join('origins', 'origins.id', 'visits.origin_id')
->get();
``
will give us: 
> Method join does not exist.


I am trying to figure out how to extend ../vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php to "understand" the search() method. 

Any suggestions are welcome!

sergionader left a reply on Laravel 5.5/Scout: How To Extend Scout To Use Eloquent Joins? • 10 months ago

No ideas, guys?

I believe that more people have been faced (or facing) it as having a searchable and sortable grid is a common need. Thanks?

13th November, 2017

sergionader started a new conversation Laravel 5.5/Scout: How To Extend Scout To Use Eloquent Joins? • 10 months ago

Hello. This is my first post here and have to say I am glad to join the Laracasts community! Let's go, then!

I am using Laravel/Scout/Elasticsearch via https://packagist.org/packages/babenkoivan/scout-elasticsearch-driver and I have this situation:

  1. To search, I must use a model like this:
$visits = Visit::search("canada")->with(['origin', 'profile', 'user'])->paginate(10);

It works very well.`

  1. As you can see, this model is related to three other tables: origins (that are countries), profile and users. The way everything is set, I can search for "canada" and get all the visits that came from Canada, what is fine as well.

  2. The result is shown in a grid using paginate(), what works well, too.

  3. However, if I want to sort the grid by Origins -- for everything I read and tried so far -- I can't use the $model::search('canada')->with(...) approach. Instead, I have to use something like

$visits = DB::table('visits') 
->join('origins', 'origins.id', 'visits.origin_id')
->orderby($sort_column, $sort_az_za)
->paginate(10);

This is the thing: the search() will not work with the DB::table('visits') syntax and Visit::search("canada")->with(....)... approach does not allow me to sort by a field that is not in the Visits table. BTW,

Visit::search("$query")->join('origins', 'origins.id', 'visits.origin_id')...

will not work as well.

The question is: how can I search and sort the results by any field I want?

I thought that it should be possible to extend Scout to search DB::table('TABLE') or to try to sort directly via ES -- though I would prefer to keep all the code bound to the "Laravel way".

If extending the DB::table('TABLE') is a way, could someone point me where to start?

Other than that, any other ideas/insights?

Thanks!

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.