mediax

Experience

4,670

1 Best Reply Awards

  • Member Since 1 Year Ago
  • 26 Lessons Completed
  • 0 Favorites

29th May, 2017

mediax started a new conversation Reset Value On Other Elements By Save? • 5 months ago

I have in my database around 30 entries and there is a field "preselected" it means if it is marked then this value should be preselected in frontend.

If I open a element and set preselected then I get in database value "1", but how can I set all other elements to "0"? Because only 1 element should be preselected...?

mediax started a new conversation Field Validation, Not Required But Unique? • 5 months ago

I have a validation like: email|unique:contacts, this is ok. but how can I handle this field as non-required and validate only if informations are there?

At the moment after first submit where email is empty then this is as "unique marked" and the user is not able to create further elements with empty mail?

22nd May, 2017

mediax left a reply on How To Handle/filter Elements From Relation? • 6 months ago

@EventFellows it's recommended to use get() directly in blade template?

@Snapey I want to get all actions from a film which are done.

21st May, 2017

mediax left a reply on How To Handle/filter Elements From Relation? • 6 months ago

I have created scope:

public function scopeDone($query)
{
    return $query->where('done', 1);
}

And the call is exactly like in previous post $film->actions()->done()

So I get there no results but entries in database exists.

The local scope is in model action, is there still something others to check?

mediax started a new conversation How To Handle/filter Elements From Relation? • 6 months ago

I have 2 models, Film and Action, my relation is:

In model Film I have following relation:

public function actions()
    {
        return $this->hasMany('App\Models\Action', 'film_id');
    }

In table actions I have a bool field called "done"

How can I filter now by using this relation like: $film->actions->DONE or $film->actions->NOT_DONE

18th May, 2017

mediax left a reply on Delete Foreign Key With Migrate Reset? • 6 months ago

@jimmy0699 I get the same error, I tried also to do in both migrations...

mediax started a new conversation Delete Foreign Key With Migrate Reset? • 6 months ago

When I try to run php artisan migrate reset I get following errors:

SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table `blog_groups`) 

SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails  

In the function down() I tried to add:

Schema::table('blog_groups', function($table) { $table->dropForeign('blog_groups_item_id_foreign');
});

But this don't works I get the same error. What I'm doing wrong here?

If I use Schema::enableForeignKeyConstraints(); and Schema::disableForeignKeyConstraints(); is this dangerous for production system after deployment?

15th May, 2017

mediax left a reply on Run Commands In Command? • 6 months ago

exec('php artisan migrate:reset');
exec('php artisan migrate');
exec('php artisan db:seed');

14th May, 2017

mediax left a reply on Manipulate With Foreach In Blade? • 6 months ago

@Snapey & @jlrdw thanks for your help, this solved my problem: https://laravel.com/docs/5.4/blade#the-loop-variable

with $loop->iteration I solved my problems :)

12th May, 2017

mediax left a reply on Manipulate With Foreach In Blade? • 6 months ago

@Snapey

I have result from my controller like this: https://drive.google.com/file/d/0B1_PFw--3o74d3NXc2F4MGFTdmc/view (expense and income)

I want to make a if request for example if expense result is finished then make a "hr-tag" between this results to have more visual difference?

mediax started a new conversation Manipulate With Foreach In Blade? • 6 months ago

I have in my table 500 entries, 300 has for example: position top, and the rest has position bottom. how can I add a "" when position top is finished?

18th April, 2017

mediax started a new conversation DB::table Request Get Only Date From "created_at" Field? • 7 months ago

I want to create a stat how many items are created by user today, but the problem is the "created_at" field has also a time, how can I do this request with ignoring time?

DB::table('users')
->join('items', 'users.id', '=', 'items.user_id')->select('*')
->where('items.user_id', '=', $user_id)->where('categories.created_at', '=', Carbon::now()->format('Y-m-d'))

29th March, 2017

mediax started a new conversation Using Cache To Decrease Sql Requests? • 7 months ago

I wish to decrease sql requests in my app, can I set cache on route? If it is not possible on route, how can I do it in controller?

Is the cahce in controller to set on return?

My example:

return response()->json($list)

27th February, 2017

mediax started a new conversation Insert Element With Subelements, Check For Errrors Before Save? (like Transaction) • 8 months ago

I have a form to create events with their members, the code is:

$event = new Event;
$event->user_id = auth()->user()->id;
$event->save();

foreach ($all_elements as $index => $element) {
    if (isset($element['select'])) {
        $event_member = new EventMember;
        $event_member->event_id = $event->id;
        $event_member->member_id = $element['member_id'];
        $event_member->notes = $element['notes'];
        $event_member->free_entry = 0;
        $event_member->save();
    }
}

How can I check if there are no errors then save all, otherwise nothing save and show a error? I mean something like transaction...

10th January, 2017

mediax started a new conversation Validate Rule If Value Not Empty? • 10 months ago

I want to make a image upload, and validation rule is mimes:jpeg,jpg,png,gif|max:10000 this is ok. but I want don't to validate if value is empty.

So if value is empty I get "Call to a member function save() on null"

How can I disable validation if value is empty? with 'sometimes' or 'present' is the same error...

26th December, 2016

mediax left a reply on Is Creating My Database Using Migrations Mandatory ? • 10 months ago

@PoissonBleu It is not mandatory, but in a few months you will do it, 99%...

Simple example: If you have to do a copy of you project then with php artisan migrate you will have your full DB structure, otherwise you have to copy your DB, make db empty etc...

For me is most important by migrations that I can keep a good view over relations...

23rd December, 2016

mediax left a reply on Controllers: "Controllers\Controller" Use Auth()? • 11 months ago

I thought it is allowed like here:

public function __construct()
    {
        $this->middleware(function ($request, $next) {
            $this->projects = Auth::user()->projects;

            return $next($request);
        });
    }

But there is the same error in my laravel...

It means I cannot use it in construct?

mediax left a reply on Controllers: "Controllers\Controller" Use Auth()? • 11 months ago

I get there only null, Laravel Framework version 5.3.24.

But my version is newer then: 5.3.4, right?

mediax started a new conversation Controllers Main "Controllers\Controller" Use Auth()? • 11 months ago

I need in my \app\Controllers\Controller.php a query to get some value for the complete system, but the problem is there don't work auth()->user()->id

Something like:

public function __construct(Request $request) {
SomeModel::where('some_id', $this->some->id)->where('user_id', auth()->user()->id)->get();
}

Error message: Trying to get property of non-object

Problem is exactly auth()->user()->id because if I give hardcoded auth user id then it works...

Is there any other way to get auth user id?

19th December, 2016

mediax left a reply on Miltilingual Site But Without Language Code? • 11 months ago

This plugin is not compatible with laravel 5.3 what I use, is there no any possibility from laravel if I give locale string from user table to set it in header as language?

18th December, 2016

mediax started a new conversation Miltilingual Site But Without Language Code? • 11 months ago

I want to implement more languages into my app, but every user should have his language, how it is to do without language string visible? It's like in every backoffice...

8th December, 2016

mediax left a reply on Relation Between 3 Tables? • 11 months ago

From Model Company to UserCompany? How can I use it in blade?

    @foreach($userAccounts as $userAccount)
            <li><a href="">{{ $userAccount->account_id }}</a></li>
        @endforeach

mediax started a new conversation Relation Between 3 Tables? • 11 months ago

I have 3 tables (also 3 models), User, Company and UserCompany, (images here: http://prntscr.com/dguedl), I have a page where I get all companies from a user this is table UserCompany, there I get company id, how can I create now relation (which type) to get company name?

7th December, 2016

mediax left a reply on Controller Created With Artisan Not Found? • 11 months ago

There is also possible to set namespace in route group like:

Route::group(['domain' => 'mydomain.com', 'namespace' => 'Shop'], function () {

});

6th December, 2016

mediax left a reply on Controller Created With Artisan Not Found? • 11 months ago

Sorry, don't seen, it works, thx :)

mediax left a reply on Controller Created With Artisan Not Found? • 11 months ago

No, I created this with following command: php artisan make:controller Shop/ProductController

composer dumpauto, it's done, but the same error.

mediax left a reply on Controller Created With Artisan Not Found? • 11 months ago

@clay There is a typo, but there should stay "Shop" because this is a folder inside "Controllers" with namespace MyProject\Http\Controllers\Shop, it is not allowed to create sub-folder in Controllres folder and place there new controllers?

mediax left a reply on Controller Created With Artisan Not Found? • 11 months ago

I tried to call it in route, [email protected], I think the problem is in my folder "Shop" under controllers, is it not allowed or have I to set something others?

mediax started a new conversation Controller Created With Artisan Not Found? • 11 months ago

I created my controller with following command: php artisan make:controller Shop/ProductController, the controller is placed on the right place under /app/Controllers/Shop/ProductController.php, the namespace is MyProject\Http\Controllers\Shop, the error message is following:

ReflectionException in Container.php line 749:
Class MyProject\Http\Controllers\ ProductController does not exist

29th November, 2016

mediax started a new conversation Subdomain Routing/service As Account? • 11 months ago

I want to set subdomain as slug for every user after registration, to do this I created separate a new table like "accounts", my questions are following, is this virtual host definition correct?

<VirtualHost *:80> DocumentRoot "/PATH/partlycrm/public" ServerName partlycrm.dev ServerAlias *.partlycrm.dev </VirtualHost>

What is to set in hosts file to get subdomain automatically after registration?

28th October, 2016

mediax started a new conversation Element Changes Save In Separate Table? • 1 year ago

I have a classic create() function to create elements, but changes I wish to save in a separate table, like history. There is table: element_changes and also model created named ElementChange, but in my ElementController, how can I tell to save it in a separate table?

Classic create function:

    public function create(Request $request) 
        $item = new Item();
        $item->fill($request->old());
        return view('items.create', compact('item'));
    }

25th October, 2016

mediax left a reply on How To Create If Request On Unique Values? • 1 year ago

Thank you @Thijs & @tomi

mediax started a new conversation How To Create If Request On Unique Values? • 1 year ago

My table has field "title" which is unique, if I type again already saved value I get SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry, how can I create the correct request in controller to give a error message by double value?

24th October, 2016

mediax started a new conversation Custom Middleware, Alerts Missing? • 1 year ago

I created a custom middleware which work as needed, but now are all alerts and messages missing, how can I add it again? The head of my middleware is:

namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;

22nd October, 2016

mediax left a reply on Restrict Access For Non-admin Group Trough Middleware? • 1 year ago

I get now this error message FatalErrorException in AdminMiddleware.php line 18: Class 'App\Http\Middleware\Auth' not found

I added this code on the top and now it works: use Illuminate\Support\Facades\Auth;

19th October, 2016

mediax left a reply on Restrict Access For Non-admin Group Trough Middleware? • 1 year ago

I tried it so:

    public function __construct() {
        protected $guard;
    }

Error message is: ```syntax error, unexpected 'protected' (T_PROTECTED)````

How can I initialize $guard without errors?

mediax left a reply on Function Store() Don't Insert Only One Field Data Missing • 1 year ago

@bestmomo & @zachleigh thanks to both, it solved my problem :)

mediax started a new conversation Function Store() Don't Insert Only One Field Data Missing • 1 year ago

In my item table I have a user_id field which is a relation with user table, my store function ignore this values during store process

 public function store(Request $request){
        $input = Input::except(['_token']);
        $input['is_published'] = $request->has('is_published');
        $input['user_id'] = Auth::user()->id;

        Item::create($input);
        return redirect()->route('items.index')->with('success', 'Your item was successfully stored!');
    }

If I do output with dd($input); then I see this id, everything other is correct but not user_id field...

mediax left a reply on Restrict Access For Non-admin Group Trough Middleware? • 1 year ago

Changed, but still the same problem

mediax left a reply on Restrict Access For Non-admin Group Trough Middleware? • 1 year ago

@maitrefrantz thank you

I added still this code: ```use Illuminate\Support\Facades\Auth;``

but now if I try to access admin area I get this error: Undefined variable: guard

Is there something still to import?

18th October, 2016

mediax started a new conversation Restrict Access For Non-admin Group Trough Middleware? • 1 year ago

I have a field in my users table called "is_admin", and have a route group "/admin", my question is where and what I have to change in middleware to restrict access for non-admin users?

12th October, 2016

mediax left a reply on Insert User ID In Relation Field? • 1 year ago

After I added 'user_id' to $fillable it works.

Can I add here checkboxes also?

$page = Auth::user()->pageUsers()->save(new Page($request->all()));

Because I wish to use here also my model functions.

11th October, 2016

mediax left a reply on Insert User ID In Relation Field? • 1 year ago

@Mo7sin @edoc Yes, it works, but now I have problem if checkbox is checked, the code for checkbox is:

$input['is_published'] = $request->has('is_published');

mediax left a reply on Insert User ID In Relation Field? • 1 year ago

@Mo7sin I tried so, but without success, my model functions are there:

Page:

public function user() {
        return $this->belongsTo('App\Models\User');
    }

User:

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

Is there everything or do I have to set still something?

mediax started a new conversation Insert User ID In Relation Field? • 1 year ago

I created a relation between 'user' and my 'page' table, now I want store user id in my page table to have a creator, my controller file is:

    public function store(Request $request) {
        $input = Input::except(['_token']);
        $input['is_published'] = $request->has('is_published');

        $id = Auth::user()->id; // So I get my logged user ID
        //$request->has('user_id') = $id; - not working
        //$input['user_id'] = $request->has($id); - not working
        Page::create($input); 
        return redirect()->route('pages.index')->with('success', 'Your item was successfully stored!');
    }
```

How can I give this ID in my 'pages' table during saving the page?

7th October, 2016

mediax left a reply on Checkbox Update In Controller File? • 1 year ago

This is nomore required?

$page->fill($request->all());
$page->save();

Why my store function not works? I tried to implement the same method...?

    public function store(Request $request)
    {
        $page = new Page();

        $input = Input::except(['_token']);
        $input['is_published'] = $request->has('is_published');
        $page->save();

        return redirect()->route('pages.index')->with('success', 'Your item was successfully stored!');
    }
```

As error message I get
***QueryException in Connection.php line 761: SQLSTATE[HY000]: General error: 1364 Field 'title' doesn't have a default value (SQL: insert into `pages` (`updated_at`, `created_at`) values (2016-10-07 08:52:08, 2016-10-07 08:52:08))**

6th October, 2016

mediax started a new conversation Checkbox Update In Controller File? • 1 year ago

I'm sorry for this question, but I'm very confused, I wan to update my checkbox value in database like published or not published with a boolean value.

In controller I added this code:

        $input = Input::except(['_token']);
        if ($request->get('is_published') == 'on') {
            $page->is_published = 1;
            $page->update($input);
        } else {
            $page->is_published = 0;
            $page->update($input);
        }

// MY COMPLETE UPDATE FUNCTION IS:

    public function update(Request $request, $id)
    {
        $page = Page::find($id);
        $input = Input::except(['_token']);

        if ($request->get('is_published') == 'on') {
            $page->is_published = 1;
            $page->update($input);
        } else {
            $page->is_published = 0;
            $page->update($input);
        }
        
        $page->fill($request->all());
        $page->save();

        return redirect()->route('pages.edit', $page->id)->with('success', 'Page updated!');
    }

I'm really sorry, my prevous sources were: https://laracasts.com/discuss/channels/laravel/how-to-save-the-values-of-checkbox-to-database http://stackoverflow.com/questions/28299999/laravel-check-checkbox-if-true-or-false-then-update-database https://laracasts.com/discuss/channels/code-review/checkbox-array-oldvalue and much more...

What I do wrong here? Is there possible to create a function if I have more checkboxes...?

5th October, 2016

mediax left a reply on Route URL With 2 Parameters? Get Only 404 Page • 1 year ago

@Ori it works perfectly, many thanks :)

mediax left a reply on WYSIWIG/Markdown Editor • 1 year ago

I use sommernote and it's nice, simple...

4th October, 2016

mediax left a reply on Route URL With 2 Parameters? Get Only 404 Page • 1 year ago

Done, many thanks for your help!

Edit Your Profile
Update

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