rumm.an

Experience

70,540

42 Best Reply Awards

  • Member Since 11 Months Ago
  • 417 Lessons Completed
  • 0 Favorites

29th June, 2018

rumm.an left a reply on Redirect User To A Specific Page If He Acesses A Conference With Id That Dont Exist • 3 weeks ago

@adamjhn did you try what I gave you? Is it giving any error? I think it should be working. Let us know if you tried that.

rumm.an left a reply on One To Many To One Relationship • 3 weeks ago

Did you try hasManyThrough relationship. See docs.

rumm.an left a reply on Laravel Auth::User Error • 3 weeks ago

It depends, if your application breaks or something unexpected happens. I cannot tell.

rumm.an left a reply on How To Make Select Filters? • 3 weeks ago

@Pradeepkumar I wont suggest returnin an html string as a response, instead return json response and render the data as required using javascript.

rumm.an left a reply on Laravel File Store Path • 3 weeks ago

for keys that exist in both arrays, the elements from the left-hand array will be used.

This is why we need to filter the request. maybe he is getting a logo from array which is an UploadedFile therefore, giving a temp directory. And as a result, using + discards the 'logo' => $path from the right hand array and uses the logo from left hand array.

rumm.an left a reply on Laravel File Store Path • 3 weeks ago

@Yorki But, according to his results, it seems like he might have disabled the mass assignment.

rumm.an left a reply on To Much Products • 3 weeks ago

You can directly fetch related Products:

$products = Product::where('company_id', 1)
    ->where("name", "like", "%$term%")
    ->orWhere("code", "like", "%$term%")
    ->orderBy( "name" )
    ->get();

rumm.an left a reply on Laravel File Store Path • 3 weeks ago

use only method on request:

$game->create($request->only(['name', 'or', 'some', 'other', 'values']) + ['user_id' => \Auth::id(), 'logo' => $path]);

rumm.an left a reply on Laravel Auth::User Error • 3 weeks ago

Seems like you are using JWTAuthentication. I am not much familiar with JWTAuthentication, so probably somebody else will help you. :)

rumm.an left a reply on Redirect User To A Specific Page If He Acesses A Conference With Id That Dont Exist • 3 weeks ago

This should get the job done.

 public function admin($id){
        if($conference = Conference::find($id) && Gate::allows('access-management-area', $conference)) {
            return view('conference.admin')->with('conference',$conference);
        }
        return redirect('/');
 }

rumm.an left a reply on Laravel Auth::User Error • 3 weeks ago

or if you are using api authentication, make sure you are passing proper tokens in your ajax requests.

rumm.an left a reply on Laravel Auth::User Error • 3 weeks ago

This is very much intended.

You can change the code depending on what you should do in case the user is not logged in.

But probably, you should return a 403 response and handle it in your Vue app, maybe show a modal or redirect to login page.

rumm.an left a reply on Protecting A Route So Only Authenticated Users Can See It • 3 weeks ago

you can create a custom middleware if you want it to be accessed only by Administrators:

use this command to create a middleware class:

php artisan make:middleware MustBeAdmin

In your app/Http/Middlewares/MustBeAdmin.php:

    public function handle($request, Closure $next)
    {
        if (!auth()->check() || !auth()->user()->isAdmin ) {
            return redirect('/'); //redirect to home
        }

        return $next($request);
    }

In your config/app.php add route middlware by appending to $routesMiddleware array:

$routesMiddlware = [
    .... 
    'must-be-admin' => \App\Http\Middleware\MustBeAdmin::class,
];

Now, in your routes simply add this middleware:

Route::get('/panel-de-administrador', '[email protected]')->middleware('must-be-admin');

rumm.an left a reply on Laravel Auth::User Error • 3 weeks ago

Try this:

public function index(Request $request)
{
    if(auth()->guest()) {
    return response()->json([], 403); //empty response with a 403 status i.e 'Forbidden'
    }
    $materials = EducationalMaterials::paginate(10);
    $all_materials = EducationalMaterialsResource::collection($materials);
    $user_class_id = Auth::user()->student_class_id; // throws up the error here.
    $filtered = $all_materials->where('class_id', $user_class_id); //retrieve only those materials which are allotted for the class the user is in.
    return EducationalMaterialsResource::collection($filtered);
}

rumm.an left a reply on Laravel Auth::User Error • 3 weeks ago

@geekshub you need to call function, use (). It should be dd(Auth::user()). I am sure you would get null. Either use a auth middleware or conditionally return a different response if user is not logged in.

rumm.an left a reply on Associating Models Through BelongsToMany Relationships • 3 weeks ago

It is covered in the docs. See, under the heading Nested Eager Loading.

rumm.an left a reply on Associating Models Through BelongsToMany Relationships • 3 weeks ago

If you are trying to load nested relations, use '.' (dot) syntax:

$job = Job::find($id)->with('operations.risks.measures')->get();
return view('jobs.show', compact('job'));

27th June, 2018

rumm.an left a reply on Example Of Manually Creating Paginator (Laravel 5+) • 3 weeks ago

If you need array, use eloquent and chain toArray() method. Its fairly simple. Here is the example:

$users = User::where('votes', '>', 100)->paginate(15)->toArray();
dd($users); //You will find it is an array!

rumm.an left a reply on Error In @section • 3 weeks ago

you dont need {{ }} with blade directive, you can simply pass variables as associative array. This way:

@section('ogtype', ['nodeType' => $node->type])

But I dont think you would be getting any benefit out of it. because it seems little illogical to pass variable in a @section. Where do you want to access this variable? If you are trying to make use of this variable in parent view. then you should pass this variable in @extends instead of @section.

rumm.an left a reply on Font Awesome 5 Using Laravel-Mix On Laravel 5.5 • 3 weeks ago

If you are using vue an official component package is available from fontawesome vue-fontawesome. Fairly, easy to use with 3 steps:

  • Install package
  • Register component
  • and use it ;)

Here is the documentation.

26th June, 2018

rumm.an left a reply on Search Multiple Tables For A Search Term • 3 weeks ago

@akLearn I always forget that! Anyways, I have updated. I'm glad it helped you. :)

25th June, 2018

rumm.an left a reply on Migration Array With Relation • 4 weeks ago

Read about seeding in Laravel, here

rumm.an left a reply on Search Multiple Tables For A Search Term • 4 weeks ago

You would not need to use with here, using callbacks with with method filters only the relationship i.e User not the Model itself i.e Album. whereHas is probably what you need. You can read about it in docs

Here is how you can get desired results:

Album::orWhere('title', 'LIKE', '%' .$input. '%')
->orWhereHas('user', function($q) {
    return $q->where('name', 'LIKE', '%' . $input . '%');
})->orWhereHas('tracks', function($q) {
    return $q->where('title', 'LIKE', '%'. $input . '%');
})->get();

This should work for you. I have not tested this, let me know if it works or not.

rumm.an left a reply on Tinymce Not Working • 4 weeks ago

You forgot this for post.description.

computed: {
    descriptionSnippet: function () {
        var div = document.createElement("div");
        div.innerHTML = this.post.description; //Error was here, now it should work.
        return div.textContent.slice(0,100);
    }
} 

rumm.an left a reply on Laravel 5.6 Session Persistence Issue • 4 weeks ago

Thats wierd.

rumm.an left a reply on Laravel 5.6 Session Persistence Issue • 4 weeks ago

@rizwan157 I think you have not overriden username method in from AuthenticatesUsers trait. If not you should, and return the string (in your case it is 'username') that represents the column that is used to log the user in.

public function username()
{  
    return 'username';
}

rumm.an left a reply on Laravel 5.6 Session Persistence Issue • 4 weeks ago

@rizwan157 Are you sure that you have not messed up with vendor Files? Can you try removing vendor files and doing composer install and then clear all the caches.

Also, it would be helpful. If you let us know when does this happen? when a user with id 1 logs in and it becomes the user 2. I mean does is happen on the very next request or on the login request itself?

22nd June, 2018

rumm.an left a reply on Laravel • 1 month ago

"do my homework for me".

Haha! seriously.

rumm.an left a reply on Laravel 5.6 Session Persistence Issue • 1 month ago

use laravel-debugbar to debug this problem.

rumm.an left a reply on Security Issue No1 Suggestion: Masking By Default The Information That Resides In .env File! • 1 month ago

@klodj Laravel is not a service you have paid for and dont talk its reputation is at risk, you are losing your own reputation talking non-sense here. Laravel is an open source framework if you can make it better then contribute.

Yes, its better to encrypt keys. But the point is, if you are getting all of those values on error page, then its not a problem with the framework, its you. You have not setup your application properly. People are telling you how you can fix your own problem, if you dont want to follow the solutions provided here, please dont talk non-sense. Your arguments dont make any sense.

If you cant deloy your application securely, you can't blame the framework. If you dont know the framework well, you should learn it first.

rumm.an left a reply on If Else Condition Not Working • 1 month ago

You code seems illogical. You want to compare two ranks? right? $rateerank and $raterrank should store ranks. But your queries are giving you some ids that too, your $raterrank would be a Collection not a number. Why are you comparing 2 Collections.

Let me know what $ratee and $rater stores. If $ratee[2] is the rank of ratee and $rater[2] is the rank of rater, then you dont need any queries. you can simple compare the ranks.

if($ratee[2] > $rater[2]) {
    // ratee's rank is higher.
}

rumm.an left a reply on Laravel 5.4 Error 'The Only Supported Ciphers Are AES-128-CBC And AES-256-CBC With The Correct Key Lengths.' When Deploying To Shared Hosting • 1 month ago

Does your shared hosting provider allow you to change the document root of your site? If you can do that, you can simply upload your local project (including .env file) to server with no change in any of files.

7th June, 2018

rumm.an left a reply on BelongsToMany Relationship • 1 month ago

This should do the trick if you ultimately need to sync the many to many relationship.

$legals = LegalEntity::find($legalIds);
$legals->each->brands()->sync($brandIds);

rumm.an left a reply on BelongsToMany Relationship • 1 month ago

if (!empty($brands) && !in_array($brand->id, $brands)) continue;

Why performing this check? Is it possible for some brands to be empty while some not?

rumm.an left a reply on [Guards & Middlewares] Trying To Make A Route Not Accessible By Guest But Accessible By Any (two In This Case) Of Guards. • 1 month ago

Solved it! Anyways. Had to Dig into Authenticate Middleware

Route::get('/schemes', "[email protected]")->middleware('auth:web,cpanel');

If any body else run into this problem, this works very well.

rumm.an started a new conversation [Guards & Middlewares] Trying To Make A Route Not Accessible By Guest But Accessible By Any (two In This Case) Of Guards. • 1 month ago

I have two guards setup web (which is set to default) and admin (which uses admins table). Now, I have ran into this problem where I have a route which I want any of them to access but guest should not acccess.

Example 1:

route('/no-guest-user-or-admin', '[email protected]')->middleware('auth');

This example uses the default guard i.e web. only normal users can access.

Example 2:

route('/no-guest-user-or-admin', '[email protected]')->middleware('auth:web');

This example uses the only specified guard i.e web. Only normal users can access.

Example 3:

route('/no-guest-user-or-admin', '[email protected]')->middleware('auth:admin');

This example uses the only specified guard i.e admin Only admins can access.

What I want

route('/no-guest-user-or-admin', '[email protected]')->middleware('solution');

so that, it checks both the guards and if either of them is logged in, then allow other wise dont.

I can try creating a custom middleware, I need to know how can I trigger other middlewares from this custom middleware with a 'OR' logic. But, before that, is there a way which laravel provides?

Thanks for Help!

20th May, 2018

rumm.an left a reply on Not Working Button Delete Post At Laravel 5 • 2 months ago

Make sure your route doesn't clash with 'show' route. You should use DELETE request method.

15th April, 2018

rumm.an left a reply on Unique Indexes On A Composite Key • 3 months ago

I'm not sure about if there is an available validation rule. You can check for the existence of such field like so. Or, You may also extract this to a custom validation rule.

\DB::table('table')
    ->where('car', request('car'))
    ->where('city', request('city))
    ->exists()

orRule object my seem like this:

class CompositeUnique implements Rule {
    public function __construct($column) 
    {
        $this->column = $column;
    }

    public function passes($attribute, $value)
    {
        return \DB::table('table')
            ->where($attribute, $value)
            ->where('city', request('city))
            ->exists();
    }

    public function message()
    {
        return "The :attribute,{$this->column} must be unique.";
    }
}

then in your controller you can add validation to any one of the columns:

request()->validate([
    'car' => ['required', new CompositeUnique('city')],
    'city' => ['required'],
]);

rumm.an left a reply on Pass Variable From Layout (@extend) To View (@yield) • 3 months ago

If your template has access to a variable then all your views which extend this template should have access to all those variables. You dont need to explicitly pass variables.

rumm.an left a reply on Request Token Via Passport Grant Client • 3 months ago

Well, I am not an expert with API Authentication so, probably someone else may help you out if my answers dont make sense to you.

rumm.an left a reply on Request Token Via Passport Grant Client • 3 months ago

I didn't Look through the documentation there was something else going in my mind. I think it is not possible.

If you are building an API, you Client id and secret are not supposed to change once in production. This is what I think. There are other ways where you can just post username and password to get the access token, e.g using token session driver. But that is considered insecure, Although I am not sure about it. I have used it, works well. But I am not sure about its securty.

The POST route /oauth/token should not need to then contain the predefined params based on this documentation.

On the very next line they have shown the example. Ofcourse, client's information is required, its like which client is asking for access token for which user. You probably dont want the concept of Password Grant Clients. I do not think there's anything wrong with the documentation. It is well supported with examples.

14th April, 2018

rumm.an left a reply on Laravel Reset Password Route Not Working • 3 months ago

Probably you are generating wrong link in the email. Show you email blade or markdown file.

rumm.an left a reply on Request Token Via Passport Grant Client • 3 months ago

it bugs me that something apparently simple didn't run for me.

You can think of client as an application that consumes your API. The application supposed to have its client_id and client_secretto authorize that it can request tokens, then for which user you want token? give login credentials (which application takes from user generally), i.e email and password.

Then what is that you dont understand?

rumm.an left a reply on Request Token Via Passport Grant Client • 3 months ago

Show your request from Postman. If it still doesnt work.

rumm.an left a reply on Request Token Via Passport Grant Client • 3 months ago

wait. Password grant client requires some additional information.

  • Grant Type
  • ClientID
  • ClientSecret
  • User Email
  • User Password

look in the docs

rumm.an left a reply on Image Not Showing On Local • 3 months ago

see the location which is being loaded on your browser dev Tools. Make sure file exists there. Also make sure if the file is located in your storage directory you have made link in public directory.

rumm.an left a reply on Array Of Objects With Eloquent Model • 3 months ago

What you object is like? you cannot check if an array contains a specific object. Instead, You should check id the array contains an object having a certain value.

$newFamilyArray is an array of objects. $child can be one of it.

You should have a Memebers only in your array. so that I can say $newFamilyArray is an array containing Members, and each memeber can have realtionships like childrens or attributes like marital_status, age on the basis of those attributes you should determine if the member is a child. Or if you want to ensure if the two child are same then they shoud have the same id( primary key).

Edit Your Profile
Update

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