Changeset f457265 for app


Ignore:
Timestamp:
02/24/21 21:58:42 (4 years ago)
Author:
Berat Kjufliju <kufliju@…>
Branches:
master
Children:
ff9da8b
Parents:
0c07a90
Message:

ADD technoweek offer, companies

Location:
app
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • app/Http/Controllers/Blog/BlogController.php

    r0c07a90 rf457265  
    44
    55use App\Http\Requests\Blog\CommentRequest;
     6use App\Http\Requests\Blog\CompanyRequest;
    67use App\Http\Requests\Blog\PostLikeRequest;
    78use App\Http\Requests\Blog\PostUnlikeRequest;
     9use App\Models\Company;
    810use App\Models\Tag;
    911use App\Models\Like;
     
    1517use App\Http\Controllers\Controller;
    1618use App\Notifications\NewCommentAdded;
     19use Illuminate\Support\Facades\DB;
    1720
    1821class BlogController extends Controller
     
    226229        ]);
    227230    }
     231
     232    public function storeCompany(CompanyRequest $request)
     233    {
     234        DB::transaction(function () use ($request) {
     235
     236            $company = new Company();
     237            $company->name = $request->name;
     238            $company->website = $request->website;
     239            $company->email = $request->email;
     240
     241            $company->save();
     242
     243            if ($company->wasRecentlyCreated) {
     244                $this->disableOfferModal();
     245            }
     246        });
     247
     248        return redirect()->route("blog.index");
     249    }
     250
     251    public function disableOffer()
     252    {
     253        $this->disableOfferModal();
     254        return redirect()->route("blog.index");
     255    }
     256
     257    private function disableOfferModal()
     258    {
     259        if (!session()->has("offer_disabled")) {
     260            session()->push("offer_disabled", true);
     261        }
     262    }
    228263}
  • app/Http/Controllers/Dashboard/IndexController.php

    r0c07a90 rf457265  
    3636            "allPosts" => Post::count(),
    3737            "currentUserPosts" => Post::where("user_id", auth()->user()->id)->count(),
    38             "users" => User::count(),
     38            "users" => !is_null(auth()->user()->company) ? auth()->user()->company->users->count() : User::count(),
    3939            "total_comments" => Comment::count(),
    4040            "comments" => auth()->user()->comments->count()
  • app/Http/Controllers/Dashboard/UsersController.php

    r0c07a90 rf457265  
    55use App\Helpers\Alert;
    66use App\Http\Requests\Dashboard\NewUserRequest;
     7use App\Models\Company;
    78use App\Models\Role;
    89use App\Models\User;
     
    4748            $user->verify_token = $user->generateVerifyToken();
    4849
    49             $user->role_id = $request->userRole;
     50            if ($request->has("company_id") || !is_null(auth()->user()->company_id)) {
     51                $user->company_id = $request->has("company_id") || auth()->user()->company_id;
     52                $user->role_id = 1;
     53            } else {
     54                $user->role_id = $request->userRole;
     55            }
    5056
    5157            $user->save();
    5258
    53             $user->userProfile()->create([
     59            $userProfile = [
    5460                "profile_link" => $user->generateProfileLink($request->name, $request->surname),
    5561                "technoblog_email" => $user->generateTechnoblogEmail($request->name, $request->surname)
    56             ]);
     62            ];
     63
     64            if ($request->has("company_owner")) {
     65                $userProfile["is_company_profile"] = true;
     66            }
     67
     68            $user->userProfile()->create($userProfile);
    5769
    5870            $user->notify(new WelcomeUser($user));
    5971
    6072            Alert::flash("New user added successfully");
    61 
    6273        });
    6374
  • app/Http/Requests/Dashboard/NewUserRequest.php

    r0c07a90 rf457265  
    2525    public function rules()
    2626    {
    27         return [
     27        $rules = [
    2828            "name" => "required|alpha|min:2|max:255",
    2929            "surname" => "required|alpha|min:2|max:255",
     
    3232            "email" => "required|string|email|max:255|unique:users",
    3333            "username" => "required|alpha_dash|min:8|unique:users,username",
    34             "userRole" => "required|exists:roles,id"
    3534        ];
     35
     36        if (!$this->has("company_id")) {
     37            $rules["userRole"] = "required|exists:roles,id";
     38        }
     39
     40        return $rules;
    3641    }
    3742
  • app/Models/User.php

    r0c07a90 rf457265  
    5353    }
    5454
     55    public function company()
     56    {
     57        return $this->belongsTo(Company::class);
     58    }
     59
    5560    public function userProfile()
    5661    {
  • app/Models/UserProfile.php

    r0c07a90 rf457265  
    1313        "technoblog_email",
    1414        "user_id",
     15        "is_company_profile",
    1516        "profile_link",
    1617        "short_bio",
Note: See TracChangeset for help on using the changeset viewer.