Jump to content


  • Posts

  • Joined

  • Last visited

osherdo's Achievements


Member (2/5)




Community Answers

  1. @Jackues1 ok I get you. Well I think the accurate question I wanted to ask for this specific thread,regardless of Laravel framework - How can I reuse a php method (suppose it contains the logic for authenticating a user) in a function?
  2. @Jacques1 thanks for that. So I understood the quoted part from your reply, and I think I may have misunderstood you.
  3. @OrpheanBeholderScryDoubt I think the second solution will be better. I still don't get why I will need to call the method in the constructor as well. @Dark Administrator this is what I am trying to figure
  4. I am using Laravel framework. I want to authenticate a user on all functions available in my code. I did not understood the constructor method quite right, and the docs were hard to follow as well. Assuming I have this code: public function __construct() { // Constructor for checking user's auth after a while. $this->middleware('auth'); if (!Auth::check()) { return redirect('auth/login'); } function something() { // How do I call it to work inside this function? } Thanks for helping.
  5. @OrpheanBeholderScryDoubt thanks for the suggestion and reference. Good to know about it.
  6. unfortunately using this: [] returns an error: syntax error, unexpected '[', expecting '('
  7. It seems that only this works: public function authorize($ability, $arguments = array()) because using the other one, or using them both as an arguments returns this error: (I am using Laravel, and it returns this) Declaration of App\Http\Controllers\DropzoneController::authorize() should be compatible with App\Http\Controllers\Controller::authorize($ability, $arguments = Array) I am now getting an error of Laravel, so that'll do for now. much thanks!
  8. I have this code: class DropzoneController extends Controller { public function __construct() { $this->middleware('auth'); if (!Auth::check()) { return redirect('auth/login'); } $this->user = Auth::user(); } public function index() { return view('dropzone_demo'); } public function uploadFiles() { $message="Profile Image Created"; $input = Input::all(); $rules = array( 'file' => 'image|max:3000', ); $validation = Validator::make($input, $rules); if ($validation->fails()) { return Response::make($validation->errors->first(), 400); } $destinationPath = 'uploads'; // upload path: public/uploads $extension = Input::file('file')->getClientOriginalExtension(); // getting file extension $fileName = rand(11111, 99999) . '.' . $extension; // renameing image $upload_success = Input::file('file')->move($destinationPath, $fileName); // uploading file to given path if ($upload_success) { return Response::json('success', 200); } else { return Response::json('error', 400); } // attaching the profile image to the authenticated user. $user->profileImage()->create([ 'filename' => $filename ]); Session::flash('new_profile_image', 'Profile Photo Updated!'); } public function authorize($ability, $arguments = Array) { // set to true instead of false return true; } } The error occurs for this line: public function authorize($ability, $arguments = Array) and it says: syntax error, unexpected ')', expecting '(' Not sure what that means. Anyone who can tell me what the issue is?
  9. ignore it, I have mistakenly tried to insert to the same id that already existed, and it thrown an error.
  10. I am trying to insert multiple rows to a column in mysql like this: INSERT INTO `sportsapp`.`exercises` (`id`, `image_path`, `name`, `category`) VALUES ('3', 'exercises/biceps/barbell_curls_lying_against_an_incline.jpg', 'Barbell Curls Lying Against An Incline', 'Biceps'), ('4','exercises/biceps/cable_hammer_curls_-_rope_attachment','Cable hammer Curls - Rope Attachment','Biceps'); I am getting an error in return: I tried to google and understand what's the reason for it, but I dont get it. I do have already a primary key, and I don't know why it generates another primary key, Could you please try to help with this?
  11. I was found out why : Next: within these: {{!! !!}} I need to comment the {{!! !!]] with the blade syntax comment: {{-- --}} around it. Solved.
  12. I am getting this error: syntax error, unexpected '}' @extends('layouts.master') @section('scripts') <script type="text/javascript" src="{!! asset('js/status.min.js') !!}"></script> @stop @section('content') {!! csrf_field() !!} @if (count($errors) > 0) <div class="alert alert-danger"> <strong>Whoops!</strong> There were some problems with your input.<br><br> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif <!-- Using laravel session --> @if(Session::has('message')) <!-- Checking if session has a variable called message. --> <div class="alert alert-info"> <li> {{ Session::get('message') }} </li> <!--if true -print the message from the insert_posts variable. --> </div> @endif {{-- You have a $user variable available representing the current Auth::user(); --}} <p>Hello, {{ $user->name }}.</p> {{-- This user has a profile whose properties you can also display --}} <p>Goals: {{ $user->profile->goals }}</p> {{-- You can also drill down to the profile's expectations --}} <p>Expectations</p> <ul class="profile-list"> @foreach($user->profile->expectations as $expectation) <li class="profile-list-item">{!! $expectation->name !!}</li> @endforeach </ul> <p><b> this is other users you may want to follow: </br></p> <ul> @foreach($mutuals as $mutual) <!-- hub/{{$mutual->user->id}} It goes to the user that matches the value of $mutual criteria. and then it goes and gets its id.This is sent to the controller for further handling.Check page source to see id's numbers. --> <!-- In the href - Passing the user to your controller --> <br><li><a href="{{URL::to('hub', [$mutual->user->id])}}" class="button button-3d" name="make_follow">Follow User</a> {!! $mutual->user->name; !!} <!-- I access the user's name property --> </li> @endforeach </ul> <form action="{{ route('createPost') }}" method="post"> <!--the form action is the method in a route called createPost --> @if(isset($message)) <!-- if the var exist and have a value it would be printed. It is used for all the notifications in this page.--> {{ $message }} @endif <br> <!-- only when a post has been submitted the varible value will show. --> <!-- telling the form the info go to this route (url). almost equal form action ="samePage" --> {!! Form::hidden('post') !!} {!! csrf_field() !!} <div class=contentWrap> <div class="test" placeholder="How's your fitness going?..." contenteditable="true"></div> </div> <div class=icons> <img alt="heart" src="http://icons.iconarchive.com/icons/succodesign/love-is-in-the-web/512/heart-icon.png"> </div> <button> Post to profile </button> <div class="errors"> </div> </form> <!-- script to check if user typed anything in the textbox before submit. both .text() and .html() return strings. It's testing if the string length is zero. trim is for removing whitespaces before and after a string. the 'submit' event is needed since it's a submit button. --> <div class="own_posts"> <p> here are your latest posts:</p> <!-- I think I should create foreach loop to iterate over each post and show it here. --> </div> <br><br> <div class="following_posts"> <p> Posts from people you're following: <p> <!-- Iterate over the followee's posts with a foreach loop: the first parameter the foreach gets is the array expression. Second element: On each iteration, the value of the current element (which is a post) is assigned to $value (second element) and the internal array pointer is advanced by one. Next: within these: {{!! !!}} --> @foreach ($get_followee_posts as $post) <form action="/html/tags/html_form_tag_action.cfm" method="post"> <textarea name="comments" id="comments" style="width:96%;height:90px;background-color:white;color:black;border:none;padding:2%;font:22px/30px sans-serif;"> {!! $post->full_post !!} </textarea> </form> @endforeach </div> @stop I tried with 2 editors and netbeans to figure why. I also use blade syntax of laravel.
  13. @Psycho are you familiar with laravel by accident?
  14. public function mutual() { $mutualUsers = DB::table('expectation_profile')->where(expectation_id,); } I am trying to write the query now. Not done with it yet.
  15. I have this pivot table: http://3.1m.yt/0_7a5sa.png I need to return multiple names of users (from users table) that have at least one expectation_id value as the current user have. How do I achieve that? Do I need to iterate with foreach loop and use Auth::user() to do this? Thanks.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.