xmarks

Hire Me

Experience

25,440

21 Best Reply Awards

  • Member Since 1 Year Ago
  • 113 Lessons Completed
  • 2 Favorites

12th June, 2018

xmarks left a reply on Backend To Frontend View Or Section • 4 months ago

ok, so what is the problem you are having trouble with at this point? writing this @foreach cycle?

Have you checked this page? https://laravel.com/docs/5.6/blade#loops

If you have a list of items to display, you could also go for DataTables: https://github.com/yajra/laravel-datatables

If you want to style your list of items, you might go for custom styles, and a pagination: https://laravel.com/docs/5.6/pagination

7th June, 2018

xmarks left a reply on What Is Best Css Framework? • 4 months ago

Well now with V4, Bootstrap has come a long way.

Laravel also comes pre-configured for Bootstrap 3 and 4 - Which you can opt-out of course. But you will need to redesign some defined layouts, such as the Pagination for example, which comes with classes for Bootstrap.

Also, note that many Packages / Plugins, made for Laravel, sometimes work with Bootstrap in mind, such as https://github.com/yajra/laravel-datatables

On the other hand, I hear good things about Bulma. you will just have to work quite a bit using it.

I can also advise Tailwind CSS which I see a lot of Laravel Developers use: https://tailwindcss.com/

xmarks left a reply on Backend To Frontend View Or Section • 4 months ago

Well you could easily just as well create a directory: resources / views / frontend where you can add all your front-end View Files.

You would also create here something like: resources / views / frontend / layouts / master.blade.php which would be your new Front End layout - if you wish to have a different design for the Front End.

Here you would load a different CSS / JS for the new layout. All your new Front End Views would reference this as the Master Layout. All your Controllers would also reference Views from this Groups.

It's quite straight-forward. Are you having trouble with something in particular?

xmarks left a reply on Laravel Iterate Through Unlimited Hierarchy Treeview Non-recursively • 4 months ago

I think it also depends on how your Database is Structured. I am guessing, same as me, you are using a single cateogires table, with fields id | name | parent_id where parent_id is referencing self.

This method is more than fine from what I last researched, but you could also go for a Nested Set Model: https://en.wikipedia.org/wiki/Nested_set_model

I found this quite complicated, but luckily there is a package for this: https://github.com/lazychaser/laravel-nestedset

xmarks left a reply on Laravel Iterate Through Unlimited Hierarchy Treeview Non-recursively • 4 months ago

You shouldn't build your HTML in the controller.

You should build a Blade View, and pass to it the $categories.

Then for each "Parent", call "Self" passing $category->childs => which will be the Parent $category of the "Recursive View". Like this:

<!-- inside category.view -->

@foreach($category->childs as $category)
        @include('category.view', [$category])
@endforeach 

As for the recursive method, I think it's fine to use it...

On the Model, I have also used a recursive call like this:

    /*
     * get All Children of Parent
     * Parent hasMany children
     */
    public function getChildren() {return $this->hasMany(self::class, 'parent_id');}

    /*
     * Department Child Relation
     * child belongs to Parent
     */
    public function parent() {return $this->belongsTo(self::class, 'parent_id');}

    /*
     * Recursive Children of ROOT Parent Categories
     * children hasMany getChildren
     */
    public function children() {return $this->getChildren()->with('children');}

Hope this helps

6th June, 2018

xmarks left a reply on Relations Issue, How To Make It Correct? • 4 months ago

Also I would add, do you need to have 2 separate tables for users and user_infos? if the relation is 1 to 1, you may just simply add the fields of user_infos to the users table, and keep the data in a single table.

Another thing I noticed:

                $table->integer('isFriendly')->length(2)->nullable($value = true);
                $table->integer('isToxic')->length(2)->nullable($value = true);
                $table->integer('isLeader')->length(2)->nullable($value = true);
                $table->integer('isFunny')->length(2)->nullable($value = true);
                $table->integer('isSkilled')->length(2)->nullable($value = true);

These seem to be True/False fields. you may want to save the data as:

                $table->boolean('isFriendly')->nullable();
                $table->boolean('isToxic')->nullable();
                $table->boolean('isLeader')->nullable();
                $table->boolean('isFunny')->nullable();
                $table->boolean('isSkilled')->nullable();

24th April, 2018

xmarks left a reply on Redirecting Back To Intended Laravel 5.5 • 5 months ago

yo, sry for late reply.

Just add the Auth Middleware to your Controller for the specific Method

So in your Controller where you are working on, the constructor would be the very first method called. Say you have a HomeController, where you redirect the user to your Home View.

You would have:

  • __constructor() - method
  • index() - method below it

In the constructor, you add the middleware to limit access to the index method.

21st March, 2018

xmarks left a reply on Forge Pointing To Wrong Website With Chrome • 6 months ago

Strange, it would seem like a problem with your Browser, since it works on other Browsers. Try:

  • Open the website with a Private Session with Chrome.
  • Try to clear the browser Cache and Cookies. I advise cCleaner: https://www.ccleaner.com/

xmarks left a reply on In ProviderRepository.php Line 208: Class Not Found • 6 months ago

Have you tried:

composer dump-autoload

20th March, 2018

xmarks left a reply on Enable/disable Required Policy From The Laravel Boilerplate Forms Dynamically. • 6 months ago

In that case, I am guessing you are getting the User Role ID, so in case your User Role ID = 1, for example, then you can write:


// somewhere before validation...
$userRole = 1; // The ID, or if it's a name, then $userRole = 'user';


{

    return [

        // ...

        'roles' => 'nullable|required_with:extra_field_1,extra_field_2|array',
       
        'extra_field_1' => 'nullable|required_if:roles,' .$userRole,

        'extra_field_2' => 'nullable|required_if:roles,' .$userRole,

}

So this should validate the extra_fields just when the "roles" field = $userRole. You just have to make sure you pass the correct value to $userRole, depending on what is passed on your Form (Some use ID as an integer, some use plain text with the role name, some use the ID as a string, so check to make sure)

19th March, 2018

xmarks left a reply on Enable/disable Required Policy From The Laravel Boilerplate Forms Dynamically. • 6 months ago

What you have right now, your field roles is required.

As such, there is no case where "Roles" field can be set to NULL, as you described above. So the extra fields "extra_field_1" and "extra_field_2" will also be required.

What I told you would be:

{

    return [

        // ...

        'roles' => 'nullable|required_with:extra_field_1,extra_field_2|array',
       
        'extra_field_1' => 'nullable|required_with:roles',

        'extra_field_2' => 'nullable|required_with:roles',

}

As this stands, the following can happen:

  • "roles", "extra_field_1", "extra_field_2" - can be all left Empty (Null, nothing selected) - Validation will pass
  • "roles", "extra_field_1", "extra_field_2" - must all have a value for the Validation to pass, else the Validation Fails

xmarks left a reply on Bridging Users, Companies And Transactions • 6 months ago

1.

I think that the only case where you should require a PivotTable company_user is if a User can belong to more than 1-company. Otherwise, it wouldn't hurt to keep the relation on the users Table.

2.

Sure, if that works for you. I do not have much experience with hasManyThrough as I have yet to make use of it, but I checked the documentation and it seems correct. You could probably simplify it since you are currently using Laravel Naming Conventions:

public function transactions()
    {
        return $this->hasManyThrough(Transaction::class, User::class);
    }

3.

Again same with the relation between users and companies. If you are certain that the relation is 1:1, then you should keep things in the same Table. I think systems (Servers, Storage and Programs) are now powerful enough to not having to worry about null-assigned fields taking up too much space.

I would think that you owe it to yourself and whoever will take care of your code later to keep things as simple and as easy to manage as possible. But again this would be a personal opinion.

I would only use a PivotTable (or Intermediate Table) for true cases of Many-To-Many Relations, like "Tags / Categories etc..." where I would check if the data has already been used before:

  • If Yes => assign the same data
  • If No => create the new data and assign it / Or Data does not exist exception Then this data, having the same ID, can be used to fetch all different Models where it has been assigned to. (Like for example, creating a Search for Posts, from certain Categories or Tags / Or Finding all Companies of a User, if more than 1 in your example)

16th March, 2018

xmarks left a reply on Enable/disable Required Policy From The Laravel Boilerplate Forms Dynamically. • 7 months ago

From what you explained, you have a:

  • role- field
  • extra_field_1
  • extra_field_2 ...

In that case, the best solution would probably be:

  • role=> nullable|required_with:extra_field_1,extra_field_2....
  • extra_field_1 => nullable|required_with:role
  • extra_field_2 => nullable|required_with:role

So, if the "role" field, passed to the Form is NULL, then nothing has been selected, and the validation will not require "extra_field_1" and "extra_field_2".

If a "role" is selected, then the Extra Fields will be required.

If a user tries to play tricks, and fills "extra_field_1" and "extra_field_2", and then empties "role" then it will also throw an exception as they are required with the "role" field.

xmarks left a reply on Bridging Users, Companies And Transactions • 7 months ago

If what you want to achieve is this command:

App\User::find(1)->transactions->get();

Then why don't you structure your Database like:

  • companies table => id | ....
  • users table => id | company_id | ...
  • transactions table => id | user_id | ...

Then add relations:

Company Model:

public function users() { return $this->hasMany(User::class); }

User Model:

public function company() { return $this->belongsTo(Company::class); }

public function transactions() { return $this->hasMany(Transaction::class); }

Transaction Model:

public function user() { return $this->belongsTo(User::class); }

Now you can have:

  • Eager Load Relation: $user = App\User::find(1)->with('transactions')->get();
  • Then the results are: $user->transactions;

xmarks left a reply on Disabling A Table / Class To Migrate Again When Migration:refresh Is Called • 7 months ago

no.

In case you do not want to call all the Migrations then you run:

php artisan migrate

Migrate:refresh will call the down() method, and then the up() Method, always.

Usually, when you want to modify a Table (add / remove a field), you create a separate Migration that will take care of that, and then simply run php artisan migrate. The New Migration will have on it's up() method something to make the necessary changes.

Check migrations listed on this Repo for example: https://github.com/Riari/laravel-forum/tree/4.0/migrations

As new changes are made to the code, any modifications to the Tables are added into New Migrations, so it does not break existing code on update.

xmarks left a reply on Report Designer For Laravel 5.5 • 7 months ago

Then I advise you check the answers on this Thread: https://laracasts.com/discuss/channels/general-discussion/how-to-get-a-print-view-of-a-page

If you do not want to eventually Print the page, then you should skip those steps, but the DOMPDF Package is a good solid solution to format A4 pages.

xmarks left a reply on Deploying My Application To Heroku Returns A Service Provider Error • 7 months ago

yeah, but you need it locally.

The Provider is taken from the "Vendor" folder. Since DerbugBar is not being installed on Heroku, then the Provider can't be found from the "Vendor" folder, and thus it's giving you the error.

So the solution: You need to install it, and then deactivate it.

How to deactivate it:

After this, DebugBar should work. If you do not want it active on Heroku, change the APP_DEBUG parameter, on your .env file, from true to false.

15th March, 2018

xmarks left a reply on Deploying My Application To Heroku Returns A Service Provider Error • 7 months ago

Then you have to take the other steps I mentioned, since you have to keep the Provider. Again:

  • when installing Debugbar, by default it is required on dev Environment. Usually Heroku is considered a production environment, so it does not install packages under dev.
  • If you want Debugbar on Heroku, you have to modify your composer.json file, and move the DebugBar Package from require-dev to require.
  • Then push your changes again. Debugbar will now install as a package, and the Service Provider class will be found.

After this, DebugBar should work. If you do not want it active on Heroku, change the APP_DEBUG parameter, on your .env file, from true to false.

xmarks left a reply on I Have An Issue On Retrieve The Image From The Storage Folder • 7 months ago

You can not access the storage folder directly like that. It is 1-level above the public path where your index.php file is located.

You should read this doc: https://laravel.com/docs/5.6/filesystem#configuration

Basically you have to create a symbolic link:

php artisan storage:link

Then you access files using the Storage facade:

  • Storage::put('avatars/1', $fileContents);
  • $contents = Storage::get('file.jpg');
  • $url = Storage::url('file.jpg');

xmarks left a reply on Deploying My Application To Heroku Returns A Service Provider Error • 7 months ago

First of all, on Laravel 5.5+ you do not need to declare a Service Provider, as it is done automatically.

Second, when installing Debugbar, by default it is required on dev Environment. Usually Heroku is considered a production environment, so it does not install packages under dev.

If you want Debugbar on Heroku, you have to modify your composer.json file, and move the DebugBar Package from require-dev to require.

Then push your changes again. Debugbar will now install as a package, and the Service Provider class will be found.

xmarks left a reply on Report Designer For Laravel 5.5 • 7 months ago

Like what sort of Report?

The simplest ones would be a table-data? You could have a look at:

Or do you have anything else specific in mind?

13th March, 2018

xmarks left a reply on Validation Of Multiple Inputs In Array • 7 months ago

I had a similar issue. To solve it, you have to check if the error is for the specific Input Field Name, like so:

<div class="input-product_code {{ $errors->has('product_code.' .$i) ? ' has-error' : '' }}">
    <input id="product_code{{ $i }}" type="text" class="form-control product_code" name="product_code[]">

    @if ($errors->has('product_code.' .$i))
        <span class="help-block">
            <strong>{{ $errors->first('product_code.' .$i) }}</strong>
        </span>
    @endif
</div>

6th March, 2018

xmarks left a reply on Laravel Roles • 7 months ago

If the data is really all different, you could do the following:

  • users table: id | role | first_name | last_name | email | password | ... other default fields of Laravel Auth
  • data_members table: id | user_id | ... Other data for Members
  • data_secretaries table: id | user_id | ... Other data for Secretaries

Relations would be:

  • User Model:
public function data_member() {return $this->belongsTo(dataMember::class);}
public function data_secretary() {return $this->belongsTo(dataSecretary::class);}
  • dataMember Model:
public function user() {return $this->hasOne(User::class);}
  • dataSecretary Model:
public function user() {return $this->hasOne(User::class);}

to get the data:

if($user->role === 'member') :
    $user->load('data_member');
else: 
    $user->load('data_secretary');
endif;

14th February, 2018

xmarks left a reply on How I Can Get Data From Multiple Models • 8 months ago

Create another Method url:

// Inside Product.php Model
public function url()
{
    return $this->belongsTo('App\CleanURL', 'clean_url', 'product_id', 'id');
}

And you can call it:

$categories = Category::with('products.url')->get();

Then you can do the following:

@foreach($category->products as $product)
    {{ $product->url }}
@endforeach

26th January, 2018

xmarks left a reply on Convert MySQL Query To Eloquent Or Query Builder • 8 months ago

while this is a late reply and you might no longer require it, and my answer is not tested, I think this will work:

$query = Sales::rightJoin(DB::raw('date(sales.created_at) = calendars.datefield'))
  ->select(
    'calendars.datefield as date',
    DB::raw('IFNULL(SUM(sales.sale_total),0) AS total')
  )
  ->whereRaw(
    'calendars.datefield between (
      SELECT MIN(DATE(created_at)) FROM sales
    ) AND (SELECT MAX(DATE(created_at)'
  )->groupBy('date')->get();

25th January, 2018

xmarks left a reply on Join Causes Duplicate Results • 8 months ago

First of all, do you really need to join the Refunds? If you need to show the data on an "if it exists" basis, then why not just eager-load it?

$processedSales = Sale::with('refunds')
    ->where('sales.user_id', Auth::user()->id)
    ->where('processed', '=', 1)
    ->where('sale_date', '>=', Carbon::now()->subDays($numberOfDays))
    ->orderBy('refunds.status', request('direction'))
    ->paginate(25);

If you do need to use the data in such a way that you are required to use join, I would also guess that not all Sales have a Refund. In that case, you'd probably want to use a leftJoin:

$processedSales = Sale::where('sales.user_id', Auth::user()->id)
    ->where('processed', '=', 1)
    ->where('sale_date', '>=', Carbon::now()->subDays($numberOfDays))
    ->leftJoin('refunds', 'sales.user_id', '=', 'refunds.user_id')
    ->orderBy('refunds.status', request('direction'))
    ->paginate(25);

More on different types of Join Here

xmarks left a reply on How To Improve User's Experience? • 8 months ago

On the latest Firefox, mobile view, you get a Javascript Error when trying to open the menu-burger, and the menu does not open at all.

And the SVG-images are overlapping with the content on smaller devices.

You should use the browser's dev-tools to check the responsiveness of every page as you scale the width of the screen from desktop-size to mobile-size.

12th January, 2018

xmarks left a reply on I Am Unable To Install Laravel On My Machine • 9 months ago

I do not know if you have solved this yet.

  • Try to Uninstall Virtualbox and Vagrant.
  • After that, go to your User Folder: C:\Users\your_user
  • Manually Delete: .vagrant.d, .VirtualBox,VirtualBox VMs
  • Run a clean-up with cCleaner: https://www.piriform.com/ccleaner/download
    • Run a Cleanup
    • Clean the Registry as well
  • Reinstall Virtualbox first
  • Reinstall Vagrant
  • Try to download the laravel box again vagrant box add laravel/homestead (Again Command Line in Administrator Model)

Also note this from the Documentation:

If you are using Windows, you may need to enable hardware virtualization (VT-x). It can usually be enabled via your BIOS. If you are using Hyper-V on a UEFI system you may additionally need to disable Hyper-V in order to access VT-x.

11th January, 2018

xmarks left a reply on Redirecting Back To Intended Laravel 5.5 • 9 months ago

Just add the Auth Middleware to your Controller for the specific Method:

/**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        // Only Authenticated Users can access Cities jSON request
        $this->middleware('auth', ['only' => [
            'specificMethod_1', 'specificMethod_2'
        ]]);
    }

Or to all Except a Specific Method:

/**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        // Only Authenticated Users can access Cities jSON request
        $this->middleware('auth', ['except' => [
            'specificMethod'
        ]]);
    }

Laravel takes care of it out-of-the-box.

If the user is required to be authenticated, they will, and then they will get redirected to where they were previously.

xmarks left a reply on I Am Unable To Install Laravel On My Machine • 9 months ago

Are you on Windows 10?

First try to run the Command-Line as Administrator.

If that does not work, I see that Vagrant 2.0.1 is reported Here to have broken something on Windows. So try to uninstall and reinstall Vagrant 2.0.0.

Although I have Vagrant 2.0.1 and everything seems to be working fine for me.

xmarks left a reply on PHP CODE IN LARAVEL • 9 months ago

You should avoid any queries inside your View.

These should be done in the Controller and/or Model Level. From your View you should simply pass a request to the Controller, and it would give you a response back into your View.

10th January, 2018

xmarks left a reply on -> OrWhereHas Failed Fetch Data From Multiple Tables • 9 months ago

You do not need to do that. Instead of:

->orWhereHas('writter', function ($query) use ($keyword) {
            $query->where('nama_penulis', 'like', '%'.$keyword.'%');
        })

You do:

->orWhereHas('writter', function ($query) use ($keyword) {
            $query->whereRaw('LOWER(nama_penulis) like ?', "%$keyword%"); // Only this needs to be changed
        })

xmarks left a reply on Handling Large Dataset (1000+) In VueJS • 9 months ago

Adding to the response from @Spillmester there is a nice package for Laravel to ease the implementation of DataTables: yajra/laravel-datatables

Search and pagination are handled server-side through AJAX.

Bootstrap 3 theme included.

This is not VUEjs, but if all you want is to show a table with pagination and searchable, I think as well that using DataTables would be your best solution.

xmarks left a reply on -> OrWhereHas Failed Fetch Data From Multiple Tables • 9 months ago

You're welcome, I am glad that worked out.

As for ilike, I thought it was not recognized on MySQL from what I have read. My solution with whereRaw was meant to add support so your application works both locally on MySQL and Live on PostgreSQL.

9th January, 2018

xmarks left a reply on -> OrWhereHas Failed Fetch Data From Multiple Tables • 9 months ago

I believe the issue might be that Postgres Does not work well with like, as for Postgres like is case sensitive while for MySQL is by default Case Insensitive. Postgres has ilike for case insensitive but that does not work with mySQL...

Try using whereRaw instead. For Example:

$query = Book::whereRaw('LOWER(judul) like ?', "%$keyword%")
    ->orWhereRaw('LOWER(label) like ?', "%$keyword%")
...

This has worked for me on Heroku with no problems.

Also, I advise:

  • Testing the code 1 by 1, as you add more conditions to see if it fails anywhere else
  • Install and enable debugbar so you can see the query that is being executed on Heroku-side
  • Install HeidiSQL which has a PostgreSQL Connection Option. I have found it useful to get the Query executed from DebugBar, and execute it on HeidiSQL to get more information on where the code was failing.

8th January, 2018

xmarks left a reply on User (client) Accounts & Sub Accounts? • 9 months ago

adding to the answer from @andonovn

You can modify the default users table, created by the laravel php artisan make:auth by adding a parent_id field (or users_id if you want to follow default Laravel naming conventions), so you will end up with (at it's simplest):

  • users table fields => | id | parent_id | name | password | created_at | updated_at |

From here, you connect users table, with itself, thus creating a parent-child relation.

When a Client, from their profile-page creates new Sub Accounts, it's ID is added to the parent_id field.

You will also require something to differentiate Default Clients from SubAccount Clients. You can:

  • Add a server-side logic, by adding a field main_account => which would be true or false for example
  • Or a server-side logic, where you check the client if they have any value in their parent_id field.
    • If parent_id = null, this is a Main Account
    • If parent_id !=null, this is a SubAccount

And you can show different Views based on this logic, with different functions (SubAccounts can not create themselves other SubAccounts)

29th December, 2017

xmarks left a reply on Should I Repeat Separate Or Reuse A Nested Controller That Has Overlapping Purpose? • 9 months ago

Could you give an example of what you actually intend to do?

If I am understanding you correctly, you intend to have 4 tables?

  • videos / Video Model / VideosController
  • skills / Skill Model / SkillsController
  • strengths / Strength Model / StrengthsController
  • flexibilities / Flexibility Model / FlexibilitiesController

And you would end up with:

  • videos table => | id | skill_id | strength_id | flexibility_id | name |
  • skills table => | id | name | other_data |...
  • strengths table => | id | name | other_data |...
  • flexibilities table => | id | name | other_data |...

Video Model would have belongsTo relation to all other tables, while all other tables would have hasMany relation to Videos:

// Video Model
public function skill() { return $this->belongsTo(Skill::class); }
public function strength() { return $this->belongsTo(Strength::class); }
public function flexibility() { return $this->belongsTo(Flexibility::class); }

// Skill Model
public function videos() { return $this->hasMany(Video::class); }

// Strength Model
public function videos() { return $this->hasMany(Video::class); }

// Flexibility Model
public function videos() { return $this->hasMany(Video::class); }

If that is the case, what kind of data would these tables store exactly? I feel you might be doing too much if there are not really that much data being stored on each separate table.

Having many tables instead of 1 isn't really making things simpler. You should focus on having simple-code, but not necessarily simpler storage for that code. The database won't mind if you have 3-4 more Columns in the videos table.

If a category could have different set of data, as you said, you could store them in the same table, and end up with null-values, but depending on the type of data, and how much data it is, I do not think it should take much more space:

  • categories table => | id | name | data_strength_1 | data_strength_2 | data_skill_1 | data_flexibility_1 | ... When you select the data, you could specify them in the select:
$strengthVideos = Video::where('category_id', '=', '1' /* strength */)->select('id', 'name', 'data_strength_1', 'data_strength_2')->get();

If 1 video can have more than 1-category, on the other hand, you can have a pivot table:

  • videos table => | id | name |
  • categories table => | id | name |
  • category_video table => | category_id | video_id |

So now you can match 1-video with many categories. And 1-category with Many Videos. This is a Many-To-Many Relationship.

xmarks left a reply on Suggestions On A How To Carry Out A Particular Task. • 9 months ago

OK so from the top of my head, here is what I am thinking:

  • First of all, all buses should have the same seat-positioning. Or you would have to have different seats from the drop-down when the user selects their seat (which is also doable). For this you can use Select2
  • I feel some form of seat-number confirmation / assignment should be available for print to the user in some way. (An e-mail with the order: bus plate, departure_time, seat_number)
  • An e-mail confirmation of the reservation should be sent to the user. In case of a conflict between 2-users trying to reserve the same seat, they should get a notification to take another reservation, or as I said above, maybe assign an empty one in case there aren't many left free, so they do not get left without a seat entirely because they could not come to the system again to change their reservation

Table structure could be:

  • buses => | id | plate?number |
  • seats => | id | bus_id | => I think this will facilitate things. For example, showing a list of seats from a specific bus. Or if in the future, you might get different bus-sizes, with different seat count
  • events => | id | bus_id |
  • reservations => | id | event_id | client_id => default(null) | seat_id | reserved => default(false) |

So here is my thinking.

  • When you create an event, you select some Buses for it.
  • On Event Creation, the reservations table will populate, with the reserved field defaulting to false and client_id defaulting to null.
  • When client wants to join an event, a list of Bus-Seats will be available, where reserved = false.
  • When user selects a Seat and Submits the form, the Appropriate reservations table will update with the user's ID, and reserved = true.
  • From here you can see which seats are still available. You can get data for the User: Event, Bus, Seat, etc.

I might have missed something but I think the core is here.

xmarks left a reply on Multirelations With 3 Tables • 9 months ago

I am not that great with programming myself. As I stated above, this is my "Personal Opinion". You can follow your own goals or wait for someone else to give their opinion which might support yours.

Games and Platforms are fine to have a relation. Did you read my post above?

Again:

Your users table should have:

  • id => primary Key

Your games table should have:

  • id => Primary Key
  • user_id => Foreign Key, related to users table // If you are saving a list of games for a User, otherwise, you can remove this as well.

Your platforms table should have:

  • id => Primary Key

You should have a Pivot Table game_platform for the relation between games and platforms, which should have these fields:

  • game_id => Foreign Key to games Table
  • platform_id => Foreign Key to platforms Table

If you want games under PC Platform then you will end up with something like:

// In your Controller
$platform = Platform::where('name', '=', 'PC')->with('games')->get();

// In your View
<ul>
    @foreach($platform->games as $game)
        <li>{{ $game->name }}</li>
    @endforeach 
</ul>

If you want users, who own a game, under PC Platform:

// Your Controller
$platform = Platform::where('name', '=', 'PC')->with('games.users')->get();

// Your View
<ul>
    <!-- list of games -->
    @foreach($platform->games as $game)
        <li>{{ $game->name }}</li>
        
        <!-- For Each Game, list of users who own it -->
        <ul>
            @foreach($game->users as $user)
                <li>{{ $user->name }}
            @endforeach 
        </ul>
    @endforeach 
</ul>

xmarks left a reply on Multirelations With 3 Tables • 9 months ago

Well first of all, I must say it is my personal opinion that this relation makes no sense. There is no reason the users table is connected to the platforms table directly. It should connect only through the games table, as I have described above.

Next, as far as I know, Laravel does not support this. So you are probably going to have to write every method yourself to Keep these data in Synchronization.

Finally, I think this might work out for your case. But again this would simply simulate three 2-way pivot tables: game_user, platform_user and game_platform. These are all ManyToMany Relations.

A Many To Many Relation is declared like this:

return $this->belongsToMany('App\Model', 'foreign_key', 'local_key', 'table_name');

So for your case, the User Model is like this:

public function games() {
    return $this->belongsToMany(Games::class, 'user_id', 'id', 'users_games_platforms');
}

public function platforms() {
    return $this->belongsToMany(Platform::class, 'user_id', 'id', 'users_games_platforms');
}

The Game Model:

public function users() {
    return $this->belongsToMany(User::class, 'game_id', 'id', 'users_games_platforms');
}

public function platforms() {
    return $this->belongsToMany(Platform::class, 'game_id', 'id', 'users_games_platforms');
}

The Platform Model:

public function users() {
    return $this->belongsToMany(User::class, 'platform_id', 'id', 'users_games_platforms');
}

public function games() {
    return $this->belongsToMany(Platform::class, 'platform_id', 'id', 'users_games_platforms');
}

So now, if the above works, you should be able to do the following:

  • $user = User::find($id)->with('platforms'); to get the Platforms of a User
  • $user = User::find($id)->with('games'); to get the Games of a User
  • $game = Game::find($id)->with('users'); to get the Users of a Game
  • $platform = Platform::find($id)->with('users'); to get the Users of a Platform

But again I seriously advise against going though with this method and follow the one I posted previously.

xmarks left a reply on If Exist Take Id If Not Create New Client • 9 months ago

You can do this:

  • Use Select2 to build a Search-Form. You can check This Tutorial.
  • While you type, the Database will be searched for a Client, which you can select and Submit, so you can for example, be taken to the Client's Page
  • If nothing is found, Select2 has an option to select what you have typed anyhow

You can then create other Routes and Controller, which will try to find the Client-ID (id would be same as name for the case where Client is not found but you selected it anyway).

In case you are dealing with a new Client, you can redirect to a New Route, where you would create this new Client, and the Client Name could be auto-filled.

xmarks left a reply on Should I Repeat Separate Or Reuse A Nested Controller That Has Overlapping Purpose? • 9 months ago

First thing that comes to mind, is this necessary?

Wouldn't it be better to have:

  • VideosController => To take care of everything
  • Have a category field in your videos table, which will save data like "skills / flexibility / strength".

So when you need to access "Strength Videos" you can do: $videos = Video::where('category', '=', 'Strength')->get();

Otherwise, you are right. You should have a VideosController, and all other controllers would extend this base-controller. Keep everything here, like validation method, store method, edit method, and so on. DRY (Don't Repeat Yourself)

xmarks left a reply on Suggestions On A How To Carry Out A Particular Task. • 9 months ago

I would have some questions:

  • Is it necessary? Or are you trying to make it fancy? Do you have a logic behind this specification?
  • Is this a Bus Service that goes around Town? with regular stops?
  • Or is it a Bus Reservation like a Taxi, for events with a specific destination, like a camping trip.
  • Do you have any method in mind to deal with users trying to get the same seat at the same time? Like an e-mail after the fact that the seat was requested a little-bit sooner by someone else?
  • Would they go back to register again or would a random empty-seat be assigned to this user who lost their reservation?

xmarks left a reply on Making A Laravel 5.4 Query On A JSON Field Containing A JSON Array • 9 months ago

Can you modify how this is stored? So that you can remove the [ ] ?

xmarks left a reply on How Can I Display Data Uniformly Insert (include Symbol,space,enter..) • 9 months ago

So you are writing this on a textarea HTML-tag? and you wish it to keep it's format?

In that case, you need to be aware first that Laravel strips some special characters when you echo something in blade using this method:

{{ $yourData }}

To stop Laravel from stripping the special characters, you need to do this:

{!! $yourData !!}

Notice: This is not safe. Some of the special characters that Laravel removes also includes things that could be used to hack your application. To avoid that, you need to strip these bad-characters Before Saving them on your database.

For that you need to Sanitize the Input before saving it. I found these packages that you might consider:

xmarks left a reply on Database Design For Ecommerce Website Example • 9 months ago

Well this all depends on your specifications.

If you are working on a project from a client, normally first thing to do would be to take the business specifications from that client and start building your Database Relations from there.

You might also look into Spark, if it's a big project, to get you started on a solid foundation. https://spark.laravel.com/

If you are doing something for yourself, the best advise I would give you would be to start small, just the bare minimum. for example:

  • categories table. Maybe do not build a parent-child relation as a start.
  • products table. Start with a name and a price. connect it to the payment system you want to build first, and then start adding to the table things like discount, tax, vat, manufacturer, magazine, and so on...

You should check some of the e-commerce solutions for Laravel:

You can check this tutorial that builds an e-commerce application from scratch, integrated with PayPal.

Hope these help

28th December, 2017

xmarks left a reply on How To Show Project Name In Limited Characters In Laravel? • 9 months ago

In your view, do this:

{{ substr($proj->project_name, 0, 10) }}

More available functions Here

xmarks left a reply on How To Build A Worklog Table By Month? • 9 months ago

It's gonna be a bit hard for me, without making tests, to provide a working answer right away, but I'll try my best.

First of all, I think you should make the transformations in your View in this case. Some of the logic in the Controller and Model. And just query the data from the Database.

projects Table

| fields | | ------ | | id | | name | | created_at | | updated_at |

worklogs Table

| fields | | ------ | | id | | project_id | | log | | created_at | | updated_at |

Query

Based on the response here, I think this should work:

$year = $request->year;

$workLogs = Project::leftJoin('worklogs' 'projects.id', '=', 'worklongs.project_id')
    ->whereRaw("(YEAR(worklongs.created_at) =  ?)", [$year]);
    ->select(
        'projects.id as id',
        'projects.name as name',
        
        DB::raw('MONTHNAME(worklogs.created_at) as month'),
        DB::raw('SUM(worklogs.id as month_total)')
    )->orderBy('id', 'month')
    ->groupBy('month')->get();

This query will need to be tweaked a little so it shows something when the month_count is 0. This should get data like below:

| id | name | month | month_total | | ------ | ------ | ------ | ------ | | 1 | project_1 | January | 5 | | 1 | project_1 | February | 10 | | 2 | project_2 | January | 15 | | 3 | project_3 | December | 4 |

Next, Group them by ID to separate Projects
$projects = $workLogs->groupBy('id');

This will give a collection, groupedBy Projects.

View

<table class="table table-striped table-responsive">
    <thead>
        <tr>
            <th>Project</th>
            <th>January</th>
            <th>February</th>
            <th>March</th>
            <th>April</th>
            <th>May</th>
            <th>June</th>
            <th>July</th>
            <th>August</th>
            <th>September</th>
            <th>October</th>
            <th>November</th>
            <th>December</th>
            <th>Total</th>
        </tr>
    </thead>
    
    <tbody>
    <!-- Treat each $projects Collection as 1-Project -->
        @foreach($projects as $project)
            <tr>
                <th scope="row">{{ $project->first()->id }}</th>
                <!-- Treat the data inside each project as 1-separate Worklog -->
                <!-- Assuming the Query is fixed above - Each month should be iterated -->
                @foreach($project->all() as $worklog)
                    <td>{{ $worklog->month_total }}</td>
                @endforeach
                <td>{{ $project->sum('month_total') }}</td> <!-- Not sure how to call this part also, need to check results -->
            </tr>
        @endforeach
    </tbody>
</table>

xmarks left a reply on How To Build A Worklog Table By Month? • 9 months ago

How do you differentiate years here?

Are worklogs from January 2016 and worklogs from January 2017 both summed-up in the same Table-cell?

Edit Your Profile
Update

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