tisuchi

Software Engineer at Avana

Experience

336,185

204 Best Reply Awards

  • Member Since 3 Years Ago
  • 1343 Lessons Completed
  • 12 Favorites

10th September, 2018

tisuchi left a reply on Laravel Visitor Counter ? • 1 week ago

@sandofvega

I have updated the link. You can try now.

5th September, 2018

tisuchi left a reply on 1 Concurrent User • 2 weeks ago

Have you tried this?

public function swapping($user) {
    $new_sessid   = \Session::getId(); //get new session_id after user sign in
    $last_session = \Session::getHandler()->read($user->last_sessid); // retrive last session

    if ($last_session) {
        if (\Session::getHandler()->destroy($user->last_sessid)) {
            // session was destroyed
        }
    }

    $user->last_sessid = $new_sessid;
    $user->save();
}

Ref: https://stackoverflow.com/questions/27938186/laravel-only-allowing-one-session-per-user-at-a-time

30th August, 2018

tisuchi left a reply on Laravel Outputs 0 Before Any Content • 3 weeks ago

Its because there is 0 before starting your html code. It's just a typo.

0<!doctype html>

It should be -

<!doctype html>
<html lang="es">
<head>
  <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="csrf-token" content="JoznVUdPwxyz7H8qWd2Np8lPiVld1GTq9BxeC2H2">

tisuchi left a reply on Must Be An Instance Of Illuminate\Http\Request, Instance Of StdClass Given • 3 weeks ago

I think you have missed this to import on top of your controller-

use Illuminate\Http\Request;

tisuchi left a reply on Contact Form Self-Email • 3 weeks ago

You have defined wrongly.

In your controller, update your code like follows-



Mail::to('[email protected]')->send(new ContactEmail($entry));

On top of your controller, don't forget to import ContactEmail like this-

use App\Mail\ ContactEmail;

Now in your ContactEmail.php file, update like this way-

<?php

namespace App\Mail;

use App\ContactEntry;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class ContactEmail extends Mailable
{
    use Queueable, SerializesModels;

    public $contactEntry;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(ContactEntry $contactEntry)
    {
        $this->contactEntry = $contactEntry;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build() {
      return $this->from('[email protected]')
                   ->view('templates.contact-email');
}

Now finally you are able to use $contactEntry as an object in contact-email.blade.php file.

Read More: https://laravel.com/docs/5.6/mail

27th August, 2018

tisuchi left a reply on Relationships Problem HasMany Laravel 5.6 • 3 weeks ago

Have you tried this in HubModel?

public function device(){
        return $this->hasMany(Device::class, 'hub_id', 'hub_id');
    }

24th August, 2018

tisuchi left a reply on Gitlab • 3 weeks ago

You need to install the Gitlab GUI. This is the fundamental concept that how do you upload in gitlab. Check here - https://about.gitlab.com/

By using the command line, you can follow this instruction- https://docs.gitlab.com/ee/gitlab-basics/start-using-git.html#add-all-changes-to-commit

tisuchi left a reply on Gitlab • 3 weeks ago

23rd August, 2018

tisuchi left a reply on Eager Loading Relationship • 4 weeks ago

Yeah, just enhanced @tomi idea a bit.

Subject::doesntHave('class_subjects')-
        ->orWhereHas('class_subjects', function($query){
            $query->where('class_id', '=', $classId)
        })
      ->get();

31st July, 2018

tisuchi left a reply on Scaling Issues Laravel Api • 1 month ago

What I have in my mind now is, indexing that lostdreamer_nl suggested too.

Although, you can take a look here- https://serversforhackers.com/laravel-perf

tisuchi left a reply on Factory Make With Relationship • 1 month ago

Have you checked this?

$users = factory(App\User::class, 3)
           ->create()
           ->each(function($u) {
                $u->posts()->save(factory(App\Post::class)->make());
            });

Check the last of the the following section called "Adding Relations To Models" https://laravel.com/docs/5.1/testing#working-with-databases

tisuchi left a reply on How To Display Name From A Table Column • 1 month ago

Simply you can apply relationships on that, I believe.

Check: https://laravel.com/docs/5.6/eloquent-relationships#one-to-one

tisuchi left a reply on Helper Function • 1 month ago

There are a few options that you can follow-

@if(Auth::check())
    
    @if(Auth::user()->type == 'admin')
        // show items only to admin user
    @else
        // show items to non-admin user
    @endif

@endif

Of course, I prefer the first option.

tisuchi left a reply on Factory Make With Relationship • 1 month ago

I believe you can. Have you checked this discussion?

https://laracasts.com/discuss/channels/eloquent/model-factories-relations

tisuchi left a reply on Laravel 5.6 Relationships -- Foreign Key • 1 month ago

Way 1:

Posts

  • id
  • title
  • category_id
public function category(){
    return $this->belongsTo('App\Category');
    // no need to put foreign key here because laravel will automatically take category_id as a foreign key
}

categories

  • id
  • name
  • description
  • post_id
public function posts(){
  return $this->hasMany('post');
  // no need to put foreign key here because laravel will automatically take care
}```

> Remember, Eloquent will automatically determine the proper foreign key column on the  Comment model. By convention, Eloquent will take the "snake case" name of the owning model and suffix it with _id. So, for this example, Eloquent will assume the foreign key on the  Comment model is post_id.


Ref: https://laravel.com/docs/5.6/eloquent-relationships#one-to-many



## Way 2 (With different primary key)

Posts
- id 
- title
- my_category_id

public function category(){ return $this->belongsTo('App\Category', 'foreign_key', 'local_key'); // Now need to provide foreign key since foreign key is not following by default style. }



categories

- id 
- name
- description
- my_post_id

public function posts(){ return $this->hasMany('post', 'foreign_key', 'local_key'); // Now need to provide foreign key since foreign key is not following by default style. }



Ref: https://laravel.com/docs/5.6/eloquent-relationships#one-to-many

tisuchi left a reply on Multiple Dropdowns Data From Controller To View Page • 1 month ago

You know, you can call other function!

For example-

public function getDistributor()
    {
        return Distributor::all('id', 'Name');
    }

    public function getBooks()
    {
        return Book::all('BookName', 'BookID');
    }
    
    public function create()
    {
        $books = $this->getBooks();
        $distributor = $htis->getDistributor();


        return view('pages.booksout')
                ->with([
                    'books' => $books,
                    'distributor' => $distributor
                ]);
    }

Note: I have just simplified your function for showing purpose only. Please take a note that, the code is not tested.

tisuchi left a reply on Laravel 5.6 Relationships -- Foreign Key • 1 month ago

In that case, you should. Otherwise, laravel won't get relationship data.

tisuchi left a reply on Multiple Dropdowns Data From Controller To View Page • 1 month ago

Just pass two values with the view-

$books  = Book::all('BookName', 'BookID'); 
 return view('viewName')
        ->with([
            'books' => $books,
            'distributor' => $distributor,
        ]);

tisuchi left a reply on Laravel 5.6 Relationships -- Foreign Key • 1 month ago

Well, laravel by default takes table primary key is id. If your primary key is different then id, for example,post_id then you should mention that.

26th July, 2018

tisuchi left a reply on How To Test Specific Test In Laravel. • 1 month ago

There are few options, that you can try-

phpunit --filter {TestMethodName}

OR

phpunit --filter {TestMethodName} {FilePath}

Take a look this discussion: https://stackoverflow.com/questions/38821326/run-only-one-unit-test-from-a-test-suite-in-laravel

tisuchi left a reply on Query Builder Where In Array • 1 month ago

A simple approach can be-

$modelObject = Model::query();
                if($request->admin_type == 'All'){
                    $modelObject->select("*");
                } else {
                    $modelObject->select(['admin_type', 'action', 'type_from']);
                }
        return $modelObject->get();

Note: Don't forget to adjust model name and column name/s.

7th July, 2018

tisuchi left a reply on Research Project Title For Bigdata • 2 months ago

Hello @Thameera

First of all, this forum is not for the purpose that you have asked. So, I would like to ask you to search here ( https://ieeexplore.ieee.org/xpl/browsePopular.jsp ) to get the latest topic in IT and Engineering sector. Besides that, you can search the latest articles on IEEE Xplore to get the idea.

In addition, you can discuss here ( http://theconferencealerts.com/discuss ) for further research related question.

31st May, 2018

tisuchi left a reply on How To Use 'use App\Profile' Like This Inside Blade • 3 months ago

Just use-

App\Profile::get();

Although, it is not the best practice to call model in view.

30th May, 2018

tisuchi left a reply on Google Autocomplete Address • 3 months ago

@deepu07

Although it's a long time, however, what I can remember, it was because of css z-index issue. That's why it was not pop up. Make sure, you don't have that.

29th May, 2018

tisuchi left a reply on Get All Team Members Job Sites If Current User Is The Owner Of The Team • 3 months ago

Since its an authorization part, you can use Gate at Laravel [1].

Another approach can be establishing relationships between user and job site. Then you just check whether that user is eligible for modify or not by using logic.

  1. https://laravel.com/docs/5.6/authorization#gates

tisuchi left a reply on Creating A Function Like Auth::user() • 3 months ago

There are few options in that case. Check it out following discussion. https://stackoverflow.com/questions/25189427/global-variable-for-all-controller-and-views

Another option that is in my mind is to use a helper function that is also accessible.

tisuchi left a reply on Print Team Names Instead Of IDs. (Laravel 5.4) • 3 months ago

In a shortcut way, I can think of-

You need to establish another relationship for team. For example-

class Match extends Model
{
    
    //realtionship for team 1
    public function team1(){
      return $this->belongsTo('App\Team', 'team_1_id');
    }

    //relationship for team 2
    public function team2(){
      return $this->belongsTo('App\Team', 'team_2_id');
    }
}

Now you can call in your view like that way-

<td align="center">{{$match->team1->name }}</td>
<td align="center">{{$match->team2->name}}</td>

Note: I assume that, in your team table, there is a column name called name where you have stored team name. If it is different name, please update in view.

tisuchi left a reply on Test Case For HTML Select Option Spoofing • 3 months ago

What is new CountryRule?

I have a suggestion for you. Never call model in your blade. It's not a best practice.

tisuchi left a reply on Creating A Function Like Auth::user() • 3 months ago

Since you are planning for global variable and if its a static data (not change frequently), then you can store this data to .env file.

####How to store? In .env file, add-

SURVEY_NAME=Name

####How to Access? You can easily call .env variable from anywhere of your application. For instance-

{{ env('SURVEY_NAME') }}

tisuchi left a reply on Base Table Or View Already Exists Migration • 3 months ago

One of the easiest way to do that by adding a line of code Schema::dropIfExists('migration'); in your migration table.

public function up()
{
    Schema::dropIfExists('migration');
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->timestamps();
    });
}

It won't refresh your data in other table.

However, if your data is not important, then you can try this-

php artisan migrate:reset 

28th May, 2018

tisuchi left a reply on Error When Running Phpunit • 3 months ago

You better show your code. It seems that you have make some mistake.

tisuchi left a reply on Refrsh-token • 3 months ago

Have you seen this?

$http = new GuzzleHttp\Client;

$response = $http->post('http://your-app.com/oauth/token', [
    'form_params' => [
        'grant_type' => 'refresh_token',
        'refresh_token' => 'the-refresh-token',
        'client_id' => 'client-id',
        'client_secret' => 'client-secret',
        'scope' => '',
    ],
]);

return json_decode((string) $response->getBody(), true);

Ref: https://laravel.com/docs/5.6/passport

tisuchi left a reply on A Way To Store Site Settings In Laravel • 3 months ago

What I can think of right now is-

  • Store everything in DB.
  • Separate the configuration data and regular admin information.
  • Fetch configuration data from db and store as an environment variable.
  • Created another config file for storing regular admin information.

tisuchi left a reply on A Way To Store Site Settings In Laravel • 3 months ago

@chori.av

Since it's somehow related to configuration, I suggest you to store in .env that is the way more secure and best practice.

tisuchi left a reply on How To Get Header Authorisation Code From Postman? • 3 months ago

@hasandev

Have you tried this? (Not tested)

public function yourControllerFunction(Request $request)
{
    $header = $request->header('Authorization');
    //some other logic
}

tisuchi left a reply on A Way To Store Site Settings In Laravel • 3 months ago

If it is after logged in as an Admin, I always prefer to store in DB.

27th May, 2018

tisuchi left a reply on How To Generate Random Token / Key? • 3 months ago

Maybe there is another approach. But I always love to use str_random() function that is a core function of PHP.

You can try this-

str_random(32)

16th May, 2018

tisuchi left a reply on TokenMismatchException In VerifyCsrfToken.php Line 68: • 4 months ago

Thank you @Shahrukh4

The problem was solved in 1 year ago in my side. :)

10th April, 2018

tisuchi left a reply on 3 Table Relationships • 5 months ago

A rough idea can be-

  • A Student belongs to a Guardian
  • A guardian has many students
  • A family belongs to a Guardian
  • A guardian has many families
  • A family has many members

Now you need to write your relationships code like that way.

tisuchi left a reply on Why My Laravel Website Is So Slow? • 5 months ago

In the local environment, you can install Debugbar and see check what makes your site slower and optimize that portion.

https://github.com/barryvdh/laravel-debugbar

tisuchi left a reply on Facaing Problem In Transfering Website • 5 months ago

In your project folder, there is a file named .env. If it is missing, go to the following repo, copy the code from there and add to your project.

https://github.com/laravel/laravel/blob/master/.env.example

tisuchi left a reply on Page Reload On Browser Back Button. • 5 months ago

I think you cannot use laravel to detect that. So, you have to use javascript to detect on the web.

Check this discussion. https://stackoverflow.com/questions/25806608/how-to-detect-browser-back-button-event-cross-browser

Edit Your Profile
Update

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