lundi 1 mai 2017

CRUD : Adding Multiple Child Records (1-n relationships) on related CRUD form?

Running: Laravel 5.3 with Laravel Backpack CRUD 3.1

I am running into situations where I have a Model that I would like to add multiple related (child) records too, using just one CRUD form. Some examples would include adding multiple files... but let's start small. I have found the following posts that have similar topics, but not clear answer on the best way to do this.

Is the best way to use the table Field Type? http://ift.tt/2pAU1Gb But, I guess the drawback is not having validation on the child records?

A similar tutorial to this one would be cool: http://ift.tt/2qwuqeR

So, an example would be where I have a Journey model and would like to add multiple Chapters to the Journey directly on the same Journey CRUD form.

Let me know if this question makes sense... and any suggestions/advice you can share.



via Chebli Mohamed

How would I call another function in the same controller and pass in inputs?

I want to be able to call another function within the same controller rather than making another api call. The issue I can't seem to work around is how to pass in input values. For illustration purposes here is some example code:

class TestController extends Controller{
    public function first(formRequest $request){
        return response()->json([Input::get('foo').'-'.Input::get('bar')]);
    }

   public function two(){
       if(Input::get('test')){
           $newInput = ['foo'=>1,'bar'=>2];
           return $this->first()//?? this is where I am not sure how to pass in input.
       }
       return response()->json(['success']);
   }
}



via Chebli Mohamed

Setup external libraries with laravel mix

I need to use an external library on web pack with laravel-mix. On web pack I should do something like this as described in the webpack docs

{
    output: {
        // export itself to a global var
        libraryTarget: "var",
        // name of the global var: "Foo"
        library: "Foo"
    },
    externals: {
        // require("jquery") is external and available
        //  on the global var jQuery
        "jquery": "jQuery"
    }
}

But I can do this with laravel mix?



via Chebli Mohamed

Using Carbon in Eloquent Query

Good day everyone,

I'm currently realising a system that lets colleagues fill in their worked hours and what they worked on. I save those into the database using a time_stamp (date) named in the table. Now I have been trying to get the values of the filled in registrations of last week (I created some dummy times). And I have been trying to use Carbon and the Eloquent query builder at the same time, and i'm completely stuck. Would anyone mind to help me out?

$currentDate = \Carbon\Carbon::now('GMT+2');

    $agoDate = $currentDate->subDays($currentDate->dayOfWeek)->subWeek();

    $weekly = Hoursregistration::pluck('date')->agoDate($currentDate);
    return $weekly;

Is the code that should pick up the dates from the db (which works). But when I try to put in the variables containing the carbon methods. It doesnt work and throw me a Method agoDate does not exist. (View: /var/www/clients/client0/web319/web/resources/views/hoursregistrations/index.blade.php) error.

I would love some help as this is crucial to my education (kind of in a tight spot rn.)



via Chebli Mohamed

laravel after signup giving error in builder.php

I am beginner in laravel. I just created a new laravel 5.4 project. Then I run

php artisan make:auth

After that I try to register the user. Now I am getting this error:

ErrorException in Builder.php line 2443:
Call to undefined method Illuminate\Database\Query\Builder::getAuthIdentifierName() (View: D:\wamp\www\crud\resources\views\welcome.blade.php)

It looks to me as error is coming from welcome.blade.php

@if (Route::has('login'))
    <div class="top-right links">
        @if (Auth::check())
            <a href="">Home</a>
        @else
            <a href="">Login</a>
            <a href="">Register</a>
        @endif
    </div>
@endif

Can anybody help me solve my problem. Thank you in advance.



via Chebli Mohamed

Laravel throws 'The bootstrap/cache directory must be present and writable' error after update

I used 'composer update', which updated a few packages. During the updating process the website still functions. However, after it says 'The compiled services file has been removed', the website doesn't load and instead says:

Exception in ProviderRepository.php line 190:
The bootstrap/cache directory must be present and writable.

The weirdest thing is, when I run 'composer update' again, the website starts to work again, until the compiled services file is removed, at which point it throws the same error again. I have already tried the usual things that should be done when this error appears (chown -R everything to the right user/group and chmod all the files and folders 664 and 775 respectively).

I don't know what to do anymore, as the error doesn't seem 'correct'..



via Chebli Mohamed

how can fill Tagit Input from database in laravel?

i am using bootstrap Tagit inputs in my project. But i am stuck how to fill it from database record. i tried the following code but its not working please help me out. Thanks in advance

Controller

public function profile() {

    $locations=User::with('visitedList','wishList')->where('id',Auth::user()->id)->get();

    return view('pages/edit-profile' , compact('locations'));
}

Print on View

<label class="col-lg-3 control-label">Already visit:</label>
          <div class="col-lg-8">
            <input type="text" value="
            @foreach ($locations[0]->visitedList as $loc)
                    

            @endforeach

            " data-role="tagsinput" id="tags" name="wish-tags" class="form-control">
          </div>



via Chebli Mohamed