jenya

jenya

Member Since 1 Year Ago

Rostov-on-Don, Russia

Experience Points 5,620
Experience Level 2

4,380 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 39
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

06 Jun
2 weeks ago

jenya left a reply on Connect MS SQL Server With Windows Domain Login And Password Entered By The User

@MSOVANI - @msovani, thank you for your answer, but it's still doesnt' work. .

05 Jun
3 weeks ago

jenya started a new conversation Connect MS SQL Server With Windows Domain Login And Password Entered By The User

Hello! I have Windows server 2012 based domain, MS SQL Server 2012, Apache 2.4 (can use IIS if it helps) and latest Laravel version. I can connect to db with sql server login and password from user input (Thanks to @bobbybouwmann):

$config = config('database.connections.sqlsrv');
$config['host'] = $request->hostname,
$config['username'] = $request->username,
$config['password'] = $request->password,
config()->set('database.connections.sqlsrv', $config);

But is it possible to connect SQl Server with Windows domain username amd password entered by the user like this:

$config = config('database.connections.sqlsrv');
$config['host'] = $request->hostname,
$config['username'] = 'MY_DOMAIN\my_user',// or [email protected]_DOMIAN
$config['password'] ='domain_account_password',
config()->set('database.connections.sqlsrv', $config);

I don't need windows auth in my project, I only need to connect database with domain user name (and password) like I do it with sql server login(domain account has the necessary permissions to work with db. Is it possible?

02 Jun
3 weeks ago

jenya left a reply on Connect DB With User Input

@bobbybouwmann thank you for a answer. You code works great, but I implement:

public function search(Request $request )
{
  try 
  {
        config(['database.connections.sqlsrv'=>
            [
              "driver" => "sqlsrv",
              "url" => null,
              "host" => "127.0.0.1",
              "port" => "1433",
              "database" => "roles",
              "username" =>$request->username,
              "password" =>$request->pass,
              "charset" => "utf8",
              "prefix" => "",
              "prefix_indexes" => true,
           ]
         ]);

      DB::connection('sqlsrv')->reconnect();
      //Get some data from db with inputed username and password
  
  } 
   
  catch (\Exception $e)
  {
    return  redirect('/') ->with('err', 'Wrong data!'); 
  }
}

It works as well. But if more than one user use this functionality to change sqlsrv connection dinamically at the same time?

01 Jun
3 weeks ago

jenya started a new conversation Connect DB With User Input

Hello. I try to connect database with hostname, username and password I get from request array like this

use DB;
............
public function checkDatabaseConnection(Request $request)
   {
      DB::purge('database.connections.sqlsrv');
    
    config(['database.connections.sqlsrv' => 
                   [
                     'host'     => $request->hostname,
                     'username' =>$request->username,
                     'password' =>$request->password
                   ]
              ]);
    
    try {
          DB::connection()->getPdo();
          echo 'good';
          dump(config('database.connections.sqlsrv'));// always return null
         //And get some data from sqlserver with this user account
        } 
    catch (\Exception $e) 
     {
        echo 'bad';
      
     }
  }  

But if I type any dummy data into input fileds function always return good...How can I really connect db with user input? Thanks)

22 May
1 month ago

jenya left a reply on Manipulate Eloquent Collection

@bobbybouwmann thank you to your answer. A great solution with map function !

21 May
1 month ago

jenya started a new conversation Manipulate Eloquent Collection

Hello. I have some eloquent collection, for example:

$task=Task::take(30)->get();
dd($task)
``` return

array:30 [ 0=>[ "NUMBER" => "100584452" "DELIVERY_DATE" => "1990-05-10 05:27:19.000" "SERVICE" => "Mail" "COUNTRY"=>"UK" "CITY"=>"London" "SUBDIVISION" => "London office" ] ...... 10=>[ "NUMBER" => "1083684452" "DELIVERY_DATE" => "1998-05-11 15:27:19.000" "SERVICE" => "Shipping" "COUNTRY"=>"USA" "CITY"=>"Austin" "SUBDIVISION" => "Texas office" ]

]

Is it possible to return smth like:

0=>[ "TRACK"=> [ "NUMBER" => "100584452" "DELIVERY_DATE" => "1990-05-10 05:27:19.000" ] "INFO"=>[ "LOCATION"=> [ "SERVICE" => "Mail" "COUNTRY"=>"UK" ] "CITY_LOCATON"=> [ "CITY"=>"London" "SUBDIVISION" => "London office" ] ] ]

Laravel version is 5.8.17
12 May
1 month ago

jenya left a reply on Telescope Links Don't Work

@RAJUSUTRA - Thank you for your answer. I allow all rules for whole document root in my Apache config, and I have same result: package looks like working, but all root are unavailiable in dashboard.

I access to my laravel app sever_ip/appname/public/pagename/ if I visit Telescope dashboard main page sever_ip/appname/public/telescope/ - dashboard main page loaded, When I visit any link from dashboard it redirect me to sever_ip/telescope/request for example and there is 404 page.

So, I go to sever_ip/appname/public/telescope/request instead - now page loaded but if I click monitoring button or play/pause buttom nothing happens and error in firefox console Error: Request failed with status code 404 in app.js line ....... (using php artisan serve command I got the same result)

I look at telescope dashboard main page layout and found that buttons has some Vue.js functionality, so I think Telescope can not found it's app.js file, but I don't to how to fix it..

11 May
1 month ago

jenya left a reply on Telescope Links Don't Work

Thank you for a answer! telescope/models - I take this url as example. All urls are unavailable: telescope/requests,telescope/queries and others.

BUT package write rows in telescope_entries_tags table, does it mean that it works normaly and I just have a problem with Apache settings or with frontend (in theory)

10 May
1 month ago

jenya started a new conversation Telescope Links Don't Work

Hello Laracasts. I use Laravel 5.8.16, Apache 2.4 on Windows 7 x64, ans MS SQL Server 2012 as DB, also I have laravel telescope package installed.

If I go to /telescope url I can see Telescope main page with all links (requests, events and so on). If I click Requests link, for example, scanning begins and there are no requests shown. But in DB there are greate amount of different records such as events queries, so on. Then I visit telescope/models url error shown The requested URL /telescope/models was not found on this server. route:list artisan command shows only name for

|        | GET|HEAD      | telescope/{view?}                                        | telescope
            | Laravel\Telescope\Http\Controllers\[email protected]```
Please help
07 May
1 month ago

jenya left a reply on Seed BelongsTo And HasMany Relations Together

@PUNKSOLID - I use php 7.3.5. Due to this wonderfull package I increase responce time in many times (I use Redis as default cache). 5000 records loading per 5 ms! Thank you for a great idea!

06 May
1 month ago

jenya left a reply on Seed BelongsTo And HasMany Relations Together

@PUNKSOLID, thank you for a answer! I call data like this:

 $records_all = Card::with(['Document',
                            'Person' => function ($q) {        
                                         $q->where('o_id','=',auth()->user()->o_id)
                                           ->with(['department', 'state']);
                                         }
        
                         ])->get();
   
  return view('cards.index ',['records_all' => $records_all]);

In this example table Documents has a 765 rows, Person 3500 rows, departments and states has 5 or 8 rows. And main table Cards has a 500 rows, and it has only fileds I need to work with, there are no unused fileds in all tables.

So, following to your advise 1,2 and 3 to optimize the response :

  1. I use eager loading
  2. I also use foreign keys in my DB (I use MS SQL Server v 2012 ent.)
  3. I optimize DB, so there are no unused fileds in all tables.

applying it , my app main page loaded in 1.62 s, of which 93.6 ms takes 20 queries (according to Debugbar info panel) (7-9 of them is light queries to another tables such as user table or user avatar loading) I use Firefox web browser and loading view with data takes 450-500 mb of RAM (I can see it in task manager, client OS in windows 7 Pro). Also I use datatables.net js lib on client side to manipulate data on client side, but I don't think in increase page loading a lot.

Is it normal for Laravel app to display such amount of data for in 1.62 s, of which 93.6 ms takes 20 queries and use 500 mb of RAM

BUT if I dump( $records_all) and load this collection application boot for 514.8 ms (three times faster - according to Debugbar info panel) and 11 queries takes 93.6 ms loading as well

If I run db seed once or twice all data from db will be loaded for 109.2ms (according to Debugbar info panel)

So, you think is it normally to load view with data in 1.62 s and all DB data in 109.ms (near 1200 rows in main table and 5000-6000 rows in related) and is my problem on serverside or on the clientside?? (sqlserver process in serverside takes only 100-200 mb of RAM) and sorry for my english))

05 May
1 month ago

jenya left a reply on Seed BelongsTo And HasMany Relations Together

@PUNKSOLID - Your solution works great! Thank you. But when i seed my tables I have another problem: Takes a lot of time to display large amount of related records in view (but if I display the same dataset with dd() function or return it into json - it takes a few seconds..) And I can't use pagination because it can't display eager loaded records correctly..

04 May
1 month ago

jenya left a reply on Seed BelongsTo And HasMany Relations Together

@Punksolid, thank you for your answer! Your advice helps me, also I use closure into factory, for exapmle

use Faker\Generator as Faker;

$factory->define(App\Card::class, function (Faker $faker) {
    return [
         'Number' => $faker->unique()->numberBetween($min = 7133, $max = 10000),
          ..........................................
         'Doc_id' => function() {
            return factory(App\Document::class)->create()->id;
           //I have a Document factory described below , so I can use it here
        },  
    ];
});
 

I have factories for Document and Document_Person models as well and I use it inside another factories

use Faker\Generator as Faker;
$factory->define(App\Person::class, function (Faker $faker) {

    return [
        'card_id' =>  function() {
            return factory(App\Card::class)->create()->id;
        },
        'doc_id' => function() {
            return factory(App\Document_Person::class)->create()->id;
        }, //I have a Document_Person factory described below , so I can use it here as well
        .............................................................
        ];
});
 

and seeding PersonSeed

<?php

use Illuminate\Database\Seeder;

class PerosonSeed extends Seeder
{
    public function run()
    {
     
        factory(App\Person::class, 300)->create();
    }
}

But problem is: seeding with factories work good and makes related record in my four tables in correct way! But it all makes 300records in Person table, 300 records in Card table , but because Card hasMany person, I want to create 300 Card records and 3 Person records for each Card records, but I still dont understand how to do it

03 May
1 month ago

jenya started a new conversation Seed BelongsTo And HasMany Relations

Hello, Laracasts! I have four models: Card,Document_Card, Person and Document_Person

Relations are:

for Card model

<?php

class Card extends Model  
{
    protected $table ='Cards';
    protected $primaryKey='id';
       
    public function Document_Card()
    {
        return $this->belongsTo('App\Documen_Card','Doc_id');
    }

   
    public function Person()
    {
        return $this->hasMany('App\Person','card_id');
    }
      
 }

for Document_Card

<?php

class Document_Card extends Model 
{   
   public function Card()
    {
        return $this->hasMany('App\Card','Doc_id');
    }
}

for Person model


class Ispol extends Model  
{
   
    protected $primaryKey='id';
    protected $table='Person';
   
    public function Document_Person()
    {
        return $this->belongsTo('App\Document_Person','doc_id');
    }

    public function Card()
    {
        return $this->belongsTo('App\Card','card_id');
    }

  
}

and Document_Person

<?php


class Document_Person extends Model 
{
   
  
    public function Person()
    {
        return $this->hasMany('App\Person','doc_id');
    }

}

I make PersonFactory

use Faker\Generator as Faker;

$factory->define(App\Person::class, function (Faker $faker) {
    return [
          .................................
        'work'=>$faker->text($maxNbChars = 90) ,
        'task'=>$faker->text($maxNbChars = 80) ,
        'number'=>$faker->numberBetween($min = 1, $max = 6),
         ............................................
        ];
});

Document_PersonFactory

use Faker\Generator as Faker;

$factory->define(App\Document_Person::class, function (Faker $faker) {
    return [
        'Date'=>$faker->dateTimeBetween($startDate = '-2 months', $endDate = '+2 months', $timezone = null),
        'Name'=>$faker->sentence($nbWords = 3, $variableNbWords = true),
    ];
});

and Document_PerosnSeed

use Illuminate\Database\Seeder;

class Documents_IspsSeed extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        factory(App\Document_Person::class, 10)->create()->each(function ($doc) {
        $doc->ispol()->save(factory(App\Ispol::class)->make());
    });
    }
} //It makes 10  Document_Person instances and put it into Person table - this relation  seeds good

as wel as Factory and Seeder for Card and dDcument_Card models

<?php
//Factory for Card Model
use Faker\Generator as Faker;

$factory->define(App\Card::class, function (Faker $faker) {
    return [
        'Number' => $faker->numberBetween($min = 7133, $max = 100000),
        'Note'=>$faker->text($maxNbChars = 60) , 
         ...................................................................................
    ];
});

and Factory for Document_Card model

<?php

use Faker\Generator as Faker;

$factory->define(App\Document_Card::class, function (Faker $faker) {
    return [
        'Description'=>$faker->sentence($nbWords = 3, $variableNbWords = true),
        ........................................................................................
    ];
});
and Seed at the end)

use Illuminate\Database\Seeder;

class DocumentSeed extends Seeder { public function run() {

 factory(App\Document_Card::class, 10)->create()->each(function ($doc) {
    $doc->ispol()->save(factory(App\Card::class)->make());
 });

} }//It makes 10 Document_Card records and put id's into Card table - so this relation seeding good as well


But question is:
how to seed 

public function Person() { return $this->hasMany('App\Person','card_id'); }

29 Apr
1 month ago
28 Apr
1 month ago

jenya started a new conversation Check If Search Pattern Has An Error Scout

Hello , Laracasts. I have latest version of Laravel and TNT as Scout driver. Is it possible to check if search string has an error, for example: user typed Tslor and I want to rise a message:

Do You mean 'Taylor'

Thanks

11 Mar
3 months ago

jenya left a reply on Download Website Content And Put It Into Db

@grenadecx thank you for answer. But you say

-You don't need collection. And then you need to parse the page for the categories you want to fetch. I agree. But how to know categories I want to fetch if news posts are published daily?

07 Mar
3 months ago

jenya left a reply on Download Website Content And Put It Into Db

@grenadecx , thank You for your answer. but in this tutorial protected $collections array is known in advance, so it can be passed into public static function scrape($collection). But if some new category can be published and it not in $collections array?

jenya started a new conversation Download Website Content And Put It Into Db

Hi! Is it possible to get and download new articles from website ( https://laravel-news.com for example), put it db (one table - header of the article, another - article body and so on ) and do it on schedule with Laravel framework? Thanks

23 Jan
5 months ago

jenya started a new conversation Authorizing Private Channels By Condition

Hello Laracasts! I use Laravel events broadcasting with socket.IO and redis to notify users if records were updated : in controller

public function update(Request $request, $id)
    {
     ......
     \Event::fire(new UpdateEvent($var));
    }

in my event

class UpdateEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $var;

    public function __construct(\App\Card $card) {
    $this->card = $card;
    }

    public function broadcastOn()
    {
       return new PrivateChannel('test-channel'.$this->card->id); 
    }

}

in channels.php

Broadcast::channel('test-channel', function ($user) {
    return auth()->user();
});

and in my view index.blade.php

socket.on("test-channel:App\Events\UpdateEvent", function(message)
  {
    //some jquery action
 }

And question is: if user who can edit card with category 'important' for example make some changes how to deny user who can't see 'important' see this changes. I use spatie/laravel-permissions package to manage permissions. Thanks!

15 Jan
5 months ago

jenya started a new conversation VentureCraft/revisionable

Hello everyone. I use latest versions of VentureCraft/revisionable package, MS SQL Server and latest version of Laravel to log model changes.

model structure is

//PostModel for example
                        $table->integer('id', true);
            $table->integer('card_id');
            $table->integer('otd_id');
            $table->integer('doc_id')->nullable();
            $table->dateTime('doc_date')->nullable();
            $table->string('work')->nullable();

When I change value of work field from empty to 'some text' an error occurs:

SQLSTATE [22018]: [Microsoft] [ODBC Driver 13 for SQL Server] [SQL Server] Error converting nvarchar "some text" value to int data type.
(SQL:insert into [revisions] 
([created_at], [key], [new_value], [old_value], [revisionable_id], [revisionable_type], [updated_at], [user_id]) 
values (2019-15-01 21:21:43.542, work, some text, , 8260, App\Post, 2019-15-01 21:21:43.542, 1023))

It seems like Venturecraft try new value of field into [revisionable_id] Anyone had the same problem?

20 Dec
6 months ago

jenya started a new conversation Paginate Related Model Data

Hello Laracasts! I try to paginate related model data in my view. Models are:

class Card extends Model 
{
   
...............................

    public function ispol()
    {
        return $this->hasMany('App\Ispol','card_id');
    }
    
 .............................   
}

and

class Comment extends Model
{
...........................
 
    public function Card()
    {
        return $this->belongsTo('App\Card');
    }
...........................
}

Retriving data in controller:

public function all(Request $request)
    {
        $records = Card::with(['Document',
                          'comment' => function ($q)
                         {
                           $q->with(['user']);
                        }
                        ])->Paginate(10);
        return view('cards.index', ['records' => $records]);
    }

And view is:

{{$records->links() }}
 
    @foreach($records as $value)
        @foreach($value->comment as $comment)
        <tr>
             <td>{{$value->number}}</td>
             <td>{{$comment->text}}</td>
        </tr>
       @endforeach
    @endforeach

So, paginate don't work correctly..

18 Dec
6 months ago

jenya left a reply on Bind A Select Field From Db

This solution helps me

@foreach($person->state as state)
{!! Form::select('city[]',['New York'=>''New York','Berlin'=>'Berlin','London'=>'London'],\App\City::where('Description','=',$state->city->Description)->pluck('Description','id'),  ['class' => 'form-control']) !!}
@endforeach 

@billmn, @Cronics - thank you very much for your help and attention

14 Dec
6 months ago

jenya left a reply on Bind A Select Field From Db

And one more stupid question please)

<? $cities = App\City::pluck('name', 'id');?>
{{ Form::model($person, array('route' => array('person.update', $person->id), 'method' => 'PUT')) }}

@foreach($person->state as $state)  

{{ Form::text('some_text1[]',$data1)}}
{{ Form::model($state)}} 

    {!! Form::select('city_id[]',$cities, null, ['id' => 'system_list','multiple' => true]) !!}

{{Form::close()}}
{{ Form::text('some_text1[]',$data1)}}
@endforeach

{{Form::close()}}

and when I check my request data using dd(request->all() some_text1 and some_text1 returns arrays form many elements (as much as they have), but city_id returns also array but array from first element only so I can't save data from form beacause loop has for example 5 itterations, but city [] has only one element

jenya left a reply on Bind A Select Field From Db

@billmn, thank you for a detailed answer! But if I want to display all Person data in foreach loop ,can I use Form::model inside Form::model like this:

{{ Form::model($person, array('route' => array('person.update', $person->id), 'method' => 'PUT')) }} 
   @foreach($person->state as $state) 
    {{ Form::model($state) }}
     //bind select liste
   {{ Form::close() }}
  @endforeach
{{ Form::close() }}
12 Dec
6 months ago

jenya left a reply on Bind A Select Field From Db

@billmn, It works great when I have two models as I described below, so great thanks to you! But...if I have another model City for example

<?php
 class City extends Model
{ 
     public function state()
    {
        return $this->hasMany('App\State');
    }
     
}

and

<?php
 class State extends Model
{ 
     public function Person()
    {
        return $this->hasMany('App\Person');
    }
     
     
    public function City()
    {
        return $this->belongsTo('App\city','city_id');
    }
     
}

So,if I use form model binding for State model

{{ Form::model($state, array('route' => array('states.update', $state->id), 'method' => 'PUT')) }} \

and I can bind State to select list in my blade like this

{{ Form::select('otdel_id', \App\State::pluck('Description', 'id'),null, array('class' => 'form-control')) }}

But can I bind select list by ```City`` model values as well

jenya left a reply on Bind A Select Field From Db

@billmn , my models are:

<?php
 class Person extends Model
{
    public function State()
    {
        return $this->belongsTo('App\State', 'state_id');
    }

}
and related

<?php
 class State extends Model
{ 

     public function Person()
    {
        return $this->hasMany('App\Person');
    }
     
   
    
}

And I want to bind state->description value in select list when I loop through Person. @Cronics, thank you for your answer, but is not necessary to do smth like this

<option value="2" selected>Two</option>
<option value="1">One</option>
<option value="3">Three</option>

I just want to have my value selected by default in my select list

11 Dec
6 months ago

jenya left a reply on Bind A Select Field From Db

@billmn, thank you for a answer. I use form model binding but I want to populate my select list with related model data? Is it possible to use form model binding with related models data too?

jenya started a new conversation Bind A Select Field From Db

Hello everyone!

I want to bind db value to <option> tag of select field so that db value will be first in select list, and other option values as well. I use Laravel collective Form package and Laravel 5.7.15. Has anyone done this?

04 Dec
6 months ago

jenya left a reply on Laravel Redisearch Indexing Problem

@munazzil , thank you for a answer. But unfortunatly, it not help. the same error ocures

The field is not a property in the index. id

jenya started a new conversation Laravel Redisearch Indexing Problem

Hello everyone. I want to use Laravel Redisearch driver for Scout in my project. I have Ubuntu 18.04 with Redis server and full-text search extension for it. ( works fine from Redis CLI, I checked). Also I installed ethanhann/Laravel-RediSearch package and counfigure scout_driver variable in .env and in config/scout.php. When I want to import my model for indexing using scout:import command, error ocures: The field is not a property in the index. id My model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
class Search_test extends Model
{
   use Searchable;
 
    protected $primaryKey ='id';
    protected $table='Search_test';
    protected $connection = pgsql';

   public function toSearchableArray()
    {
      $array =  [
            'id'      => $this->id,
            'name'    => $this->name,
            'value' => $this->value
        ];
//There are only 3 fields :id, name and value
        return $array;
    }
    public function searchableAs()
    {
        return 'search_test_index';
    }
    
}

Please help. Thanks!

15 Nov
7 months ago

jenya left a reply on Broadcast Just Added Model Data

jquery .remove() helped me))

jenya left a reply on Broadcast Just Added Model Data

@D9705996, everything works fine, thank you! But if I delete record in destroy method of my resource controller, and fire some event DeleteEvent , can I also update my laravel view ( I know what Vue is more suitable, but I still use jquery in this project)? I suppose to clear my html table and draw in again in client side

 socket.on("test-channel:App\Events\DeleteEvent", function(message){
   // clear my html table and draw in again
      });

but is where more rational way to do it?

10 Nov
7 months ago

jenya left a reply on Broadcast Just Added Model Data

Thanks! But I can see nested data in the console:

Message Recieved: 
{"event":"App\Events\TestEvent",
"data":
  {"card":{"id":2050,"Number":"2049","Note":"some note",
  "club":[
          {"id":3115,"card_id":"2050","City":"New York"},
          {"id":6165,"card_id":"2050","City":"Utah"}
         ]
  },
  "socket":null
}

But if I want to append field values into jquery like this:

$("#one").append("<tr> <td align=\'center\'> "+message.card.club.city+"</td> </tr>");

it returns undefined...

jenya left a reply on Broadcast Just Added Model Data

@D9705996, thank you for your answer! But is it possible to broadcast nested model data. For example Card belongs to Club, Club has many many Members and so on...

09 Nov
7 months ago

jenya left a reply on Broadcast Just Added Model Data

@D9705996, thank you for your answer. Works fine! But is it possible to use the same technology to display updated data as well? For example, I update name of the card from Micahel to Taylor in my controller method

$card  =Card::find($id);
$card->name ='Taylor';
$card->save(); 

And I want to change name 'Michael' to 'Taylor' in one of the td's in my blade?

jenya left a reply on Broadcast Just Added Model Data

@cmdobueno thank you for your answer. I use Laravel 5.7.5

jenya started a new conversation Broadcast Just Added Model Data

Hello, Laracasts. I want to use Laravel events broadcasting for refreshing my blade view with socket.io. When I save record I fire the event in my controller method like this:

$card  = new Card();
$card->name ='Michael';
$card->city  ='London';
$card->save(); 
\Event::fire(new TestEvent());

And append or prepend a row in my Laravel blade

<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.js"></script>
    <script>
         var socket = io('http://localhost:3004');
         socket.on("test-channel:App\Events\TestEvent", function(message){
          $("#my_table").append("<tr> <td>just text</td>....... <td>just text</td>></tr>");
         });  
//I use redis pub/sub as well
</script>

It works fine. But how can I append row with just added model fields I add in my controller method?

21 Oct
8 months ago

jenya left a reply on Sorting Coumns In View With Eager Load Records

@Snapey thank you for a answer. I want to sort results by two-three fields from each table in relationships. But how to simplify my problem using joins notnested relationships?

jenya started a new conversation Sorting Coumns In View With Eager Load Records

Hello, Laracasts! I have some data i get from related tables in controller

 $records = Card::with(['Name', 'Document',
            'doer => function ($q) {
                $q->with(['city, 'country']);
                }
        ])->get();

and pass it into view like this

 return view('cards.index', ['records' => $records']);

Is there a way to sort table consists of eager loaded records by each column on the client side?

14 Oct
8 months ago

jenya left a reply on Display Redis Data In Laravel Blade

@neilherbertuk, thank you for a answer. But if i try

@foreach($del as $value)
       <tr> 
            <td align="center">{{$value['id']}}</td>
            <td align="center"> {{$value['card_id']}}</td>
            <td align="center">{{$value['user']}} </td>
            .......
        </tr>
 @endforeach 

an error occurred -Illegal string offset 'id'

jenya started a new conversation Display Redis Data In Laravel Blade

Hello, Laracasts. I can get some data from Redis server and json encode it.

After that I try to pass it into blade view like this

  $del=json_encode(Redis::mget(Redis::keys('data_del_*')),true);
 return view('logs.index', ['del'=>$del]);
dd($del) return
["{\"id\":6167,\"card_id\":\"2025\",\"delo\":null,\"user\":\"jenya\",\"state_id\":\"1\",\"work\":null,\"fail\":null,\"user_id\":\"3\",\"deleted_at\":null,\"nach_id\":\"1\"}","{\"id\":6169,\"card_id\":\"2025\",\"delo\":null,\"user\":\"jenya\",\"state_id\":\"1\",\"work\":null,\"fail\":null,\"user_id\":\"3\",\"deleted_at\":null,\"nach_id\":null}"] "

And question is how to print value in Laravel view . I try do it in foreach loop

@foreach($delas $value)
       
       <tr> 
            <td align="center">{{$value['id']}}</td>
            <td align="center"> {{$value['card_id']}}</td>
            <td align="center">{{$value['user']}} </td>
            .......
        </tr>
    
    @endforeach

but it don't work. Pleas help. Thaks!

23 Sep
9 months ago

jenya started a new conversation Laravel Scout Indexing Of New Records

Hello, Laracasts. I use latest versions of Laravel framework and Scout package with MS SQL Server DB. To implement searching i use import command:

php artisan scout:import "App\Post"

so, post.index file in the storage directory was created and i can use search method with my model (if i update or add new data in table with my Laravel app as well !). but is it possible to consider db table changes in Scout search make not by my app but if somebody add rows in MS SQL Server table directly?? Can i basically detect db changes make outside my app by Laravel methods and for example fire event 'Record № .. was created, but not by Laravel app' ?

02 Sep
9 months ago

jenya left a reply on Using Bootsrtap 4 In Dompdf

@martinbean , thank you for your answer! But is it possible to specify name of downloaded pdf file?

jenya started a new conversation Using Bootsrtap 4 In Dompdf

Hello Laracasts! I use barryvdh/laravel-dompdf v0.8.2 and Bootstrap v4.0.0 to display some data from my DB in Laravel 5.6 app. Is it possible to use such Bootstrap features as grids, form control classes and so on.. If not possible, please tell my what you do in these case, are there others pdf packages for it? Thanks!

17 Aug
10 months ago

jenya left a reply on Can't Pass Variable To A Dompdf LoadView Method

@Cronix, thank you for your answer! I try to do

use App\Card; 
use PDF;
............
public function show($id)
    {
      $card = Card->where('id',$id)->get(); //or another model query
       $this->print_pdf($card); 
    }
//and call print_pdf method with $card parameter
public function print_pdf($card)
{
   $pdf = PDF::loadView('print.print', ['card' => $card]);
    return $pdf->download('card.pdf');
}

dd($pdf) returns some array but if i use

   $pdf = PDF::loadView('print.print', ['card' => $card]);
    return $pdf->download('card.pdf');

error occurs: Maximum execution time of 30 seconds exceeded in vendor\dompdf\dompdf\src\Css\Stylesheet.php file (i want to display in pdf not so much data, only a few rows)

16 Aug
10 months ago

jenya started a new conversation Can't Pass Variable To A Dompdf LoadView Method

Hello, Laracasts. I use dompdf for Laravel, version is 0.8.2, Laravel version is 5.6.33. And i try to load my blade view with some data into .pdf file using dompdf package. Laravel view is obtained from controller method

use App\Card;
use PDF;
............
public function show($id)
    {
      $card = Card->where('id',$id)->get(); //or another model query
     return view('print.print', ['card' => $card]);
    }

so, it's return blade view with data correclty ike this

@foreach ($card as $value)
        <div class="row">
       <div class="col-sm-7"> 
          <h4>{{$value->Number}}</h4>
         </div>
       </div>
       <div class="row">
           <div class="col-sm-12"> 
            <b>{{$value->City}}</b>
       </div>
    </div>
      {-- and so on--}
      @endforeach

Trying to load view into pdf file:

public function print_pdf()
    {    
        $pdf = PDF::loadView('print.print',array('card' =>$card));
        return $pdf->download('card.pdf');
    }

but error occurs "Undefined variable: card". Please help. Thanks

11 Aug
10 months ago

jenya started a new conversation Related Models In Query Filter

Hello, Laracast! I try to make search by my related models, parameters to query filter I pass from search form inputs. Models are:

class Card extends Model
{
    public function Doer()
    {
        return $this->hasMany('App\Doer,'card_id');
    }
}
//Card can have several Doers
class Doer extends Model
{
    public function Card()
    {
        return $this->belongsTo('App\Card');
    }
    public function City()
    {
        return $this->belongsTo('App\City','city_id');
    }
   //Doer can have several Doers
}

and

class City extends Model
{
     public function Doer()
    {
        return $this->hasMany('App\Doer','city_id');
    }
}

I want to select only Cards which number == $request->input('number') and doer only from city where city == $request->input('city') I can get Cards with Doers

$x=Card::with([
                      'Doer'=>function($query)
                              {
                               //some conditions ???
                              }
                              ])->get( );

But how to select only doer which id = City.id and City.description ==$request->input('city')?

05 Aug
10 months ago

jenya left a reply on Display Blade Data As A List, Tile Or Simple Table

@esorone, are you sure that https://github.com/Nayjest/Grids is working with Blade templating?? Have ou any examples? Nayjest/Grids works like (demo example)

public function getExample1()
    {
        $cfg = [
            'src' => 'App\User',
            'columns' => [
                'id',
                'name',
                'email',
                'country'
            ]
        ];
        $grid = Grids::make($cfg);
        $text = "<h1>Basic grid example</h1>";
        return view('demo.default', compact('grid', 'text'));
    }

and just pass $grid variable into view like this:

    <div class="container">
            <?= $grid ?>
        </div>

where here can be applied blade conditions like @if , @else and so on ?