Resin

Experience

7,390

5 Best Reply Awards

  • Member Since 2 Years Ago
  • 94 Lessons Completed
  • 0 Favorites

14th August, 2018

Resin left a reply on Avoiding Making Same Query Over And Over • 2 days ago

Ended up doing this (and it works)

public function getDefinitions($project_id)
    {
        return Cache::store('array')->remember('definitions', 1, function() use ($project_id) {
            return Definition::where('project_id', $project_id)->get();
        });

    }

Resin started a new conversation Avoiding Making Same Query Over And Over • 2 days ago

I am trying to set up a resource collection (a sub child of my parent resource collection).

For each item there is a chance that it needs some extra data for adding to ajax. Now there are quite a few items and currently I am having to get the same "extra data" for each and every item that needs it. Does anyone have any bright ideas of how to avoid doing this? My only idea is to load it all the way up in the first resource and pass it down all the way, but I hope there is a more clean way of doing it.

The structure is like this.

QuestionCollection->Question->SpecialActionsCollection

Thanks!

31st July, 2018

Resin left a reply on Factory Make With Relationship • 2 weeks ago

Yeah but sadly that requires me to add more than on question (if you set the 3 after class to one, it just returns a boolean).

Resin left a reply on Factory Make With Relationship • 2 weeks ago

As far as I understand you can only use this to persist the relationship in the database and get back the id to use as reference. It does not actually return the relation. I would need to use load() or the likes afterwards to load the relationship (which in turn would require me to persist the data using create() instead of make()

Resin started a new conversation Factory Make With Relationship • 2 weeks ago

Hi

Does anyone know if it is possible to use factories to build a model with relations? I am currently doing it this way.

$question_data = [
            'question_type' => 32,
        ];
$question = factory(Question::class)->make($question_data);
$questiontext = factory(QuestionText::class)->make();
$question->text = $questiontext;

I was hoping to be able to build it up using the factory itself.

27th July, 2018

Resin started a new conversation React BrowserRouter Refreshes Page When Using Link • 2 weeks ago

I am trying to get Laravel to work properly with react router. Sadly when using BrowserRouter and Link, the page makes a full refresh (instead of using browser history). If I switch to using HashRouter, it works as expected, but I really wan't to use the BrowserRouter.

Any hints as to how I should get it working properly?

3rd July, 2018

Resin left a reply on Post To A Route With Data NOT In A Form • 1 month ago

Use a form with hidden input fields

  @foreach($times as $time)
      {{ $time['start'] }} <input type="hidden" value="{{ $time['start'] }} >
      {{ $time['end'] }} <input type="hidden" value="{{ $time['end'] }} >
  @endforeach 

Resin left a reply on Count Quantity Of Each Registration Type Is Not Working Properly • 1 month ago

What do you get if you run

dump($registration->conference->registrationTypes);

21st June, 2018

Resin left a reply on Refresh Page Error • 1 month ago

Please use ``` on each side of your code to format it properly.

20th June, 2018

Resin left a reply on SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails • 1 month ago

Are you sure you have a row on the requisitions table with id 1? The same question for the schools table

14th June, 2018

Resin left a reply on How To Downgrade Bootstrap Version To 3.3.7 In Laravel 5.6? • 2 months ago

Try installing it specifically

Run this from the terminal

npm install <package>@<version>

Resin left a reply on Eloquent Merge Two Queries • 2 months ago

Use unions https://laravel.com/docs/5.6/queries#unions

$first = DB::table('users')
            ->whereNull('first_name');

$users = DB::table('users')
            ->whereNull('last_name')
            ->union($first)
            ->get();

13th June, 2018

Resin left a reply on Throw New MethodNotAllowedHttpException($others); • 2 months ago

Why are you passing the controller reference in the last route as an array?

Route::post('/readxsl', ['[email protected]_xsl']);

12th June, 2018

Resin left a reply on Passing String (path) From View To Controller • 2 months ago

Ah sorry I misunderstood. What you are looking for is Requests https://laravel.com/docs/5.6/requests#accessing-the-request

You can type hint it in the read_xsl() method and get the current request

To get the file simply use this. https://laravel.com/docs/5.6/requests#retrieving-uploaded-files

Resin left a reply on Passing String (path) From View To Controller • 2 months ago

return view('form')->with('path', $path);

Resin left a reply on How To Add The Color Picker For Form Element • 2 months ago

Did you try a google search? This was the first item I found. https://github.com/xiaokaike/vue-color

11th June, 2018

Resin left a reply on Podcast Download • 2 months ago

Seems that the url to the mp3 file is in the source.

Using chrome:

Right click the player and select "Inspect element" Press ctrl + F and search for "simplecast-player" The src of the element has url to the mp3 file Right click the url and select open in new tab Right click the new player and select "Save as.."

Resin left a reply on Pop Up Alert Message In Laravel • 2 months ago

Are you using ajax to insert the data or a simple form?

6th June, 2018

Resin left a reply on Call Controller Method Inside A Job Handle Method • 2 months ago

If that is necessary you are most likely doing something wrong. :) Make a common thing (say a job) that can be called from both your controller and your queue.

Resin left a reply on Hy • 2 months ago

Try

explode(', ', Input::get('telefon')->toArray()

5th June, 2018

Resin left a reply on Blank Page After Submitting Form In Laravel • 2 months ago

Like @martinbean said if it returns false there will be no output. NULL will evaluate to false and nothing will be rendered.

Resin left a reply on ErrorException (E_ERROR) Undefined Variable: Data • 2 months ago

If you dont use compact you need to pass it with a key. Otherwise laravel will have no idea that your variable is called 'data'.

$data = insurance_model::all();

return view('index', ['data' => $data]); 

or use with

$data = insurance_model::all();

return view('index')->with('data', $data); 

Resin left a reply on ErrorException (E_ERROR) Undefined Variable: Data • 2 months ago

Compact takes a string not a variable. Use it like this

$data = insurance_model::all();

return view('index',compact('data')); 

1st June, 2018

Resin left a reply on Draggable And Resizable Images Onto Background And Save Into 1 Image • 2 months ago

This is quite a big project. I would suggest starting with reading the jQuery UI docs. They have tools for resizable, draggable etc. If you have little experience with jQuery I would suggest breaking it down into smaller goals

  1. Find out how to resize and image and make it movable
  2. Find out how to swap images
  3. Find out to drag new items to your canvas etc.

31st May, 2018

Resin left a reply on Second Parameter DB::raw() • 2 months ago

Use selectRaw instead.

From the docs: The selectRaw method can be used in place of select(DB::raw(...)). This method accepts an optional array of bindings as its second argument:

Resin left a reply on Getting Data Using Eloquent/one To Many Relationship • 2 months ago

Use it like this

Route::get('/customer',function(){

    $customers=Customer::with("Country")->get();
    foreach($customers as $customer){

        echo $customer->customer_id."|".$customer->customer_name."|".$customer->country_fid."<br/>";
        echo $country->country->country_name."<br/>";


    }

});

Resin left a reply on Getting Data Using Eloquent/one To Many Relationship • 2 months ago

$customer->country

This will only get on country back.

Try:

echo $customer->country->country_name . "<br/>";

Resin left a reply on Ajax Post Submit With Laravel • 2 months ago

Please post your route

Resin left a reply on Showing Error After Uploading To Server • 2 months ago

Try installing php7-json

sudo apt-get install php7.0-json

Resin left a reply on Showing Error After Uploading To Server • 2 months ago

Which version of PHP are you using?

30th May, 2018

Resin left a reply on How To Get The First Of Many Relationship? • 2 months ago

If it is on the User model you can use.

$user->about->first();

Resin left a reply on The Last Element With Specific Class • 2 months ago

The reason is that you used $(this) which refers to the button you are clicking on. It will NEVER have the class mail_block (as this is the class of the actual blocks). You are actually already finding the correct element here

upper = $("#"+this_id+"_row").next('.main_block').attr('id');

I would suggest using variables to cache your items (best practice).

function move_down(this_id)
    {
    var row,
        row_below,
        clone,
        clone_below;

    row =  $("#"+this_id+"_row")
        
        if($(this).is($(".main_block:last"))) {
                alert("This is the last block, don't push no lower");
        return;
            } 

    row_below = row.next('.main_block')

        clone = row.clone();
        clone_below = row_below.clone();

        if(!row.is(':empty'))
            {
                row.replaceWith(clone_below);
                clone_below.replaceWith(clone);
                row_below.addClass("replaced");
            }

    }

Resin left a reply on Translating Only A Portion Of Page • 2 months ago

Try this example from w3schools where they translate based on an element id. https://www.w3schools.com/howto/howto_google_translate.asp

Resin left a reply on E_NOTICE : Type 8 -- Array To String Conversion -- At Line 7 Array • 2 months ago

Use print_r($ar) instead of echo $ar to see what you actually have to work with.

Resin left a reply on Translating Only A Portion Of Page • 2 months ago

If you wish to use google translate I already told you how :)

<div class="notranslate">
Text in english
</div>
<div>
Text to translate
</div>
<div class="notranslate">
More text in english
</div>

Resin left a reply on The Last Element With Specific Class • 2 months ago

Did you try this?

if($('#' + this_id + '_row').is($(".main_block:last"))) 
            {
                alert("This is the last block, don't push ano lower");
            } 
        else 
            {
                alert('This is not the las block with .main_block class, push is ok');
            }

Resin left a reply on Seeder For Product, Product Categories, And Product Sub Categories • 2 months ago

Try this

Schema::create('products', function (Blueprint $table) {
        $table->increments('id');
        $table->string('user_id');
        $table->string('name');
        $table->longText('description')->nullable();
        $table->integer('sub_category')->unsigned();
        $table->string('image')->nullable();
        $table->string('thumbnail')->nullable();
        $table->string('price');
        $table->string('discount')->nullable();
        $table->timestamps();
    });

    Schema::create('product_categories', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->timestamps();
    });

    Schema::create('product_sub_categories', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->integer('parent_category')->unsigned();
        $table->foreign('parent_category')->references('id')->on('product_categories')->onUpdate('cascade')->onDelete('cascade');
        $table->timestamps();
    });

Schema::table('products', function (Blueprint $table) {
            $table->foreign('sub_category')->references('id')->on('product_sub_categories')->onUpdate('cascade')->onDelete('cascade');
   });

Resin left a reply on The Last Element With Specific Class • 2 months ago

I dont see a main_block class anywhere in here?

<span class="btn btn-secondary margin_1_px " title="Cancel" onclick="move_up('<?php echo $element_value['id'];?>');" ><small><i class="fas fa-arrow-circle-up"></i> Up</small></span>

Is main_block the parent class or where is it located?

Did you perhaps mean to use

if($('#' + this_id).is($(".main_block:last"))) 
            {
                alert("This is the last block, don't push ano lower");
            } 
        else 
            {
                alert('This is not the las block with .main_block class, push is ok');
            }

Resin left a reply on The Last Element With Specific Class • 2 months ago

Can you post an example of how the function is called? The click button part.

Resin left a reply on The Last Element With Specific Class • 2 months ago

Does it register the element if you just use

if($(this).is($(".main_block"))) 
            {
                alert('This is the last block');
            } 
        else 
            {
                alert('This is not the last block with .main_block class');
            } 

My point being that $(this) might not be a .main_block at all

Resin left a reply on Translating Only A Portion Of Page • 2 months ago

Add class="notranslate" to parts to not translate https://cloud.google.com/translate/faq#technical_questions

Resin left a reply on First Time Testing. Need Advice • 2 months ago

Personally I would break this into alot smaller tests. Eg. create a file just for testing the password field.

/**
     * @group fields
    */
    public function testPasswordFieldIsRequired()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit(route('register'))
                    ->maximize()
                    ->press('Register')
                    ->assertRouteIs('register')
                    ->assertSee('The password field is required')
                    ;
        });
    }

/**
     * @group fields
    */
    public function testPasswordFieldMustHaveLength()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit(route('register'))
                    ->maximize()
                    ->press('Register')
                    ->assertRouteIs('register')
                    ->type('password','test')
                    ;
        });
    }

This is just an example, but should make it fast to stop exactly which test has been broken later on.

Resin left a reply on User Roles And Permissions • 2 months ago

I personally use bican/roles It is really easy to setup and works like a charm

https://github.com/romanbican/roles

Resin left a reply on Not Getting The Views • 2 months ago

Can you update your example code to reflect you updated code?

29th May, 2018

Resin left a reply on How To Get A Relation Between Two Indirectly Related Tables? • 2 months ago

If I understand you correctly, then what you are looking for is a hasManyThrough relationship. https://laravel.com/docs/5.6/eloquent-relationships#has-many-through

Resin left a reply on Shifting All Rows Down By 1 In Sql Using Laravel • 2 months ago

Do you intend to increase all ids by one in the table in the database? Eg. 1 becomes 2 and 2 becomes 3 etc. How many rows are we talking about?

Resin left a reply on Create Model/migration With Full Permision • 2 months ago

If you need to create it for a different user (say www-data) you can use sudo -u www-data

eg.

sudo -u www-data php artisan make:migration create_country_table

Resin left a reply on How To Call A Controller Function From Schedule And Pass Parameters • 2 months ago

I would suggest using a command for your logic instead of a controller. Then you can call the command from your controller. With that said I believe you need to use an associative array. There is a big chance this will never work with a controller.

$schedule->call('\App\Http\Controllers\[email protected]', ['user' => 32])->everyMinute();

I haven't tested this out (as I said you should not use controllers in schedules).

Resin left a reply on Store The Emoji Of Post By Laravel • 2 months ago

As I dont want to write all of your code for you I can give you a few generic suggestions instead :)

The jQuery way

  1. Write some jQuery to handle the click on an icon (you suggest using data-icon="angry" etc on the div's to easily get the right icon clicked
  2. Let the jQuery click event call a route where it can be saved (using $.ajax())
  3. Make a controller that is called from the route that has the code for saving the icon

If this makes no sense to you, I would suggest reading up on jQuery :)

The form way

  1. Put each "icon" inside a element with method POST and an action calling a route in laravel.
  2. Add a hidden input field to each form with name="icon" and value="angry" etc.
  3. Change the div icons to buttons instead (you might need to fix some css issues), with type="submit"

If this makes no sense you should read https://www.w3schools.com/html/html_forms.asp

Edit Your Profile
Update

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